pulsejet

package module
v0.0.0-...-ac3fbf7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pulsejet: lightweight rules-based engine for consuming the Bluesky jetstream

Feed a filtered stream of events as fast as possible into a rules engine with mimimal overhead.

Features

  • Works out of the box with no additional infrastructure requirements
  • Can consume jetstream by itself without using rate limited endpoints
  • Makes it possible to process events at very high rates
  • Can be configured to utilize additional infrastructure as needed
  • Designed to take advantage of future improvements to Bluesky's automod engine
Getting started

run go run ./cmd/main.go

Rewind mode

run `go run ./cmd/main.go -rewind=1

Caveats

This package contains a number of workarounds to get around the fact that the base automod engine expects a firehose of events instead of a jetstream. The base automod package is not considered stable; assume that this module is also unstable. It is intended as a starting point to help other developers get prototypes up and running but does not provide significant functionality beyond that.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockRecordRule

func MockRecordRule(c *engine.RecordContext, post *appbsky.FeedPost) error

Types

type DefaultHandler

type DefaultHandler struct {
	Engine *Engine
}

DefaultHandler is a simple handler implementation that feeds events to the rules engine. It is intentionally kept simple to make it easy to replace with a more complex handler

func (*DefaultHandler) HandleEvent

func (h *DefaultHandler) HandleEvent(ctx context.Context, event *models.Event) error

type Engine

type Engine struct {
	Core  *engine.Engine
	Rules *RuleSet
}

Engine is a class that takes in events from the jetstream and sends them to the automod Performs necessary conversions to interoperate with automod, which expects a different event format.

func NewBaseEngine

func NewBaseEngine(rules *RuleSet) Engine

NewBaseEngine is a convenience function that creates an Engine with simple default implementations. Intended to work out of the box with no additional external dependencies.

func (*Engine) ProcessAccountEvent

func (eng *Engine) ProcessAccountEvent(ctx context.Context, event *models.Event) error

Entry point for pushing account events to the automod

func (*Engine) ProcessIdentityEvent

func (eng *Engine) ProcessIdentityEvent(ctx context.Context, event *models.Event) error

Entry point for pushing identity events to the automod

func (*Engine) ProcessRecordOp

func (eng *Engine) ProcessRecordOp(ctx context.Context, event *models.Event) error

Entry point for pushing record events to the automod

type FollowRuleFunc

type FollowRuleFunc = func(c *bskyengine.RecordContext, follow *appbsky.GraphFollow) error

type Handler

type Handler interface {
	HandleEvent(ctx context.Context, event *models.Event) error
}

Handler is the basic interface for processing events from a jetstream connection

type LikeRuleFunc

type LikeRuleFunc = func(c *bskyengine.RecordContext, follow *appbsky.FeedLike) error

type MockDirectory

type MockDirectory struct {
	Handles    map[syntax.Handle]syntax.DID
	Identities map[syntax.DID]identity.Identity
}

MockDirectory provides an automod-compatible directory that skips directory lookups. Significantly reduces requirements needed to connect to the jetstream. Assumes full validation of events is not necessary.

func NewMockDirectory

func NewMockDirectory() MockDirectory

func (*MockDirectory) Insert

func (d *MockDirectory) Insert(ident identity.Identity)

func (*MockDirectory) Lookup

func (*MockDirectory) LookupDID

func (d *MockDirectory) LookupDID(ctx context.Context, did syntax.DID) (*identity.Identity, error)

func (*MockDirectory) LookupHandle

func (d *MockDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*identity.Identity, error)

func (*MockDirectory) Purge

type RepostRuleFunc

type RepostRuleFunc = func(c *bskyengine.RecordContext, follow *appbsky.FeedRepost) error

type RobustClient

type RobustClient struct {
	Client  *client.Client
	BackOff backoff.BackOff
	RetryOn func(error) bool
	// contains filtered or unexported fields
}

RobustClient is a jetstream client with automatic reconnect capability Wraps a basic client with a scheduler that tracks the event cursor for reconnects BackOff is not thread safe and should only be modified when client is inactivate

func NewRobustClient

func NewRobustClient(config *client.ClientConfig, logger *slog.Logger, scheduler client.Scheduler) (*RobustClient, error)

func (*RobustClient) ConnectAndRead

func (rc *RobustClient) ConnectAndRead(ctx context.Context, cursor *int64) error

type RuleSet

type RuleSet struct {
	FollowRules []FollowRuleFunc
	RepostRules []RepostRuleFunc
	LikeRules   []LikeRuleFunc
	// contains filtered or unexported fields
}

Ruleset defined as a wrapper as a workaround to the lack of an interface

func CreateRuleset

func CreateRuleset(rules *bskyengine.RuleSet) *RuleSet

func MockRules

func MockRules() *RuleSet

func (*RuleSet) CallRecordDeleteRules

func (r *RuleSet) CallRecordDeleteRules(c *bskyengine.RecordContext) error

func (*RuleSet) CallRecordRules

func (r *RuleSet) CallRecordRules(c *bskyengine.RecordContext) error

type Ticker

type Ticker struct {
	Scheduler client.Scheduler
	Logger    *slog.Logger
	Frequency time.Duration
	// contains filtered or unexported fields
}

Ticker is a custom scheduler that tracks event metadata. Peridocially prints event stats to log.

func (*Ticker) AddWork

func (t *Ticker) AddWork(ctx context.Context, repo string, evt *models.Event) error

func (*Ticker) Shutdown

func (t *Ticker) Shutdown()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL