workeradapter

package
v0.0.0-...-96588ac Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildEnvFromDB

func BuildEnvFromDB(opts BuildEnvOptions, siteID string, assets worker.AssetsFetcher) *worker.Env

BuildEnvFromDB loads environment variables, secrets, and all bindings for a site from the database, returning a worker.Env ready for execution.

func DeleteFile

func DeleteFile(path string) error

DeleteFile removes a file from the filesystem.

func GetD1Path

func GetD1Path(dataDir, databaseID string) string

GetD1Path returns the filesystem path for a D1 database file.

func GetDataDir

func GetDataDir() string

GetDataDir returns the data directory from the environment or a default.

Types

type BuildEnvOptions

type BuildEnvOptions struct {
	DB            *gorm.DB
	MinioClient   *minio.Client
	PresignClient *minio.Client
	PublicS3URL   string
	D1DataDir     string
	Dispatcher    worker.WorkerDispatcher
	Store         *storage.Manager
	Cache         *storage.SiteRulesCache
}

BuildEnvOptions holds the dependencies needed to build a worker Env from the database.

type CronRunner

type CronRunner struct {
	// contains filtered or unexported fields
}

CronRunner ticks every minute, evaluates schedules, and dispatches worker scheduled() handlers for matching cron entries.

func NewCronRunner

func NewCronRunner(db *gorm.DB, engine *worker.Engine, envFactory func(string) *worker.Env) *CronRunner

NewCronRunner creates and starts a CronRunner that evaluates schedules every minute. Call Shutdown() to stop it.

func (*CronRunner) Shutdown

func (cr *CronRunner) Shutdown()

Shutdown stops the cron runner and waits for it to finish.

type GORMCacheStore

type GORMCacheStore struct {
	DB     *gorm.DB
	SiteID string
}

GORMCacheStore implements worker.CacheStore using GORM.

func (*GORMCacheStore) Delete

func (cs *GORMCacheStore) Delete(cacheName, url string) (bool, error)

Delete removes a cached response. Returns true if an entry was deleted.

func (*GORMCacheStore) Match

func (cs *GORMCacheStore) Match(cacheName, url string) (*worker.CacheEntry, error)

Match retrieves a cached response for the given cache name and URL. Returns nil if not found or expired.

func (*GORMCacheStore) Put

func (cs *GORMCacheStore) Put(cacheName, url string, status int, headers string, body []byte, ttl *int) error

Put stores a response in the cache, replacing any existing entry for the URL.

type GORMDurableObjectStore

type GORMDurableObjectStore struct {
	DB *gorm.DB
}

GORMDurableObjectStore implements worker.DurableObjectStore using GORM.

func (*GORMDurableObjectStore) Delete

func (b *GORMDurableObjectStore) Delete(namespace, objectID, key string) error

Delete removes a single key.

func (*GORMDurableObjectStore) DeleteAll

func (b *GORMDurableObjectStore) DeleteAll(namespace, objectID string) error

DeleteAll removes all entries for a given object.

func (*GORMDurableObjectStore) DeleteMulti

func (b *GORMDurableObjectStore) DeleteMulti(namespace, objectID string, keys []string) (int, error)

DeleteMulti removes multiple keys, returning the count deleted.

func (*GORMDurableObjectStore) Get

func (b *GORMDurableObjectStore) Get(namespace, objectID, key string) (string, error)

Get retrieves a single value by key, returning "" if not found.

func (*GORMDurableObjectStore) GetMulti

func (b *GORMDurableObjectStore) GetMulti(namespace, objectID string, keys []string) (map[string]string, error)

GetMulti retrieves multiple values by keys.

func (*GORMDurableObjectStore) List

func (b *GORMDurableObjectStore) List(namespace, objectID, prefix string, limit int, reverse bool) ([]worker.KVPair, error)

List returns entries matching an optional prefix, with limit and reverse support.

func (*GORMDurableObjectStore) Put

func (b *GORMDurableObjectStore) Put(namespace, objectID, key, valueJSON string) error

Put upserts a single key-value pair.

func (*GORMDurableObjectStore) PutMulti

func (b *GORMDurableObjectStore) PutMulti(namespace, objectID string, entries map[string]string) error

PutMulti upserts multiple key-value pairs.

type GORMKVStore

type GORMKVStore struct {
	DB          *gorm.DB
	NamespaceID string
}

GORMKVStore implements worker.KVStore using GORM.

func (*GORMKVStore) Delete

func (kv *GORMKVStore) Delete(key string) error

Delete removes a key from the namespace.

func (*GORMKVStore) Get

func (kv *GORMKVStore) Get(key string) (string, error)

Get retrieves a value by key, returning "" if not found or expired.

func (*GORMKVStore) GetWithMetadata

func (kv *GORMKVStore) GetWithMetadata(key string) (*worker.KVValueWithMetadata, error)

GetWithMetadata retrieves a value and its metadata by key.

func (*GORMKVStore) List

func (kv *GORMKVStore) List(prefix string, limit int, cursor string) (*worker.KVListResult, error)

List returns keys (and metadata) matching a prefix, up to limit entries, with cursor-based pagination support.

func (*GORMKVStore) Put

func (kv *GORMKVStore) Put(key, value string, metadata *string, ttl *int) error

Put upserts a key-value pair with optional metadata and TTL (seconds).

type GORMQueueConsumer

type GORMQueueConsumer struct {
	DB     *gorm.DB
	SiteID string
}

GORMQueueConsumer provides server-side queue message consumption.

func (*GORMQueueConsumer) Ack

func (qc *GORMQueueConsumer) Ack(messageID string) error

Ack marks a message as acknowledged.

func (*GORMQueueConsumer) Consume

func (qc *GORMQueueConsumer) Consume(queueName string, batchSize int) ([]QueueMessage, error)

Consume retrieves up to batchSize unacked messages from the queue.

type GORMQueueSender

type GORMQueueSender struct {
	DB        *gorm.DB
	SiteID    string
	QueueName string
}

GORMQueueSender implements worker.QueueSender using GORM.

func (*GORMQueueSender) Send

func (qs *GORMQueueSender) Send(body, contentType string) (string, error)

Send creates a single message in the queue and returns its ID.

func (*GORMQueueSender) SendBatch

func (qs *GORMQueueSender) SendBatch(messages []worker.QueueMessageInput) ([]string, error)

SendBatch creates multiple messages in the queue and returns their IDs.

type LogRetentionRunner

type LogRetentionRunner struct {
	// contains filtered or unexported fields
}

LogRetentionRunner periodically deletes old worker logs.

func NewLogRetentionRunner

func NewLogRetentionRunner(db *gorm.DB, maxDays int) *LogRetentionRunner

NewLogRetentionRunner creates and starts a log retention runner that deletes worker logs older than maxDays. Ticks every hour.

func (*LogRetentionRunner) Stop

func (lr *LogRetentionRunner) Stop()

Stop stops the log retention runner and waits for it to finish.

type MinioR2Store

type MinioR2Store struct {
	Client        *minio.Client
	PresignClient *minio.Client // optional client configured with public S3 host for presigning
	BucketName    string
	PublicS3URL   string // public-facing S3 URL for direct object URLs
}

MinioR2Store implements worker.R2Store using minio-go.

func (*MinioR2Store) Delete

func (s *MinioR2Store) Delete(keys []string) error

Delete removes one or more objects by key.

func (*MinioR2Store) Get

func (s *MinioR2Store) Get(key string) ([]byte, *worker.R2Object, error)

Get retrieves an object's data and metadata.

func (*MinioR2Store) Head

func (s *MinioR2Store) Head(key string) (*worker.R2Object, error)

Head retrieves object metadata without downloading the body.

func (*MinioR2Store) List

List lists objects in the bucket with optional filtering.

func (*MinioR2Store) PresignedGetURL

func (s *MinioR2Store) PresignedGetURL(key string, expiry time.Duration) (string, error)

PresignedGetURL generates a pre-signed URL for downloading an object.

func (*MinioR2Store) PublicURL

func (s *MinioR2Store) PublicURL(key string) (string, error)

PublicURL returns the public URL for an object.

func (*MinioR2Store) Put

func (s *MinioR2Store) Put(key string, data []byte, opts worker.R2PutOptions) (*worker.R2Object, error)

Put stores an object and returns its metadata.

type PlatformDispatcher

type PlatformDispatcher struct {
	Engine     *worker.Engine
	EnvFactory func(siteID string) *worker.Env
}

PlatformDispatcher implements worker.WorkerDispatcher by delegating to an Engine.

func (*PlatformDispatcher) Execute

func (pd *PlatformDispatcher) Execute(siteID, deployKey string, env *worker.Env, req *worker.WorkerRequest) *worker.WorkerResult

Execute dispatches a worker request, optionally building the env from the factory.

type QueueMessage

type QueueMessage struct {
	ID          string `gorm:"primaryKey"`
	QueueName   string `gorm:"index"`
	Body        string
	ContentType string
	CreatedAt   time.Time
	Acked       bool   `gorm:"default:false"`
	SiteID      string `gorm:"index"`
}

QueueMessage represents a message in a queue, stored in SQLite via GORM.

func (*QueueMessage) BeforeCreate

func (q *QueueMessage) BeforeCreate(_ *gorm.DB) error

BeforeCreate generates an ID for QueueMessage if not set.

type StaticAssetsFetcher

type StaticAssetsFetcher struct {
	Store     *storage.Manager
	Cache     *storage.SiteRulesCache
	SiteID    string
	DeployKey string
	SPAMode   bool
	Domain    string
}

StaticAssetsFetcher implements worker.AssetsFetcher by replicating the static file serving pipeline (redirects, headers, rewrites, SPA fallback, 404).

func (*StaticAssetsFetcher) Fetch

Fetch processes a WorkerRequest through the static pipeline and returns the appropriate response, just as the main server would.

type StorageSourceLoader

type StorageSourceLoader struct {
	Store *storage.Manager
}

StorageSourceLoader implements worker.SourceLoader using the storage manager.

func (*StorageSourceLoader) GetWorkerScript

func (s *StorageSourceLoader) GetWorkerScript(siteID, deployKey string) (string, error)

GetWorkerScript retrieves the worker JS source for the given site and deploy key.

Jump to

Keyboard shortcuts

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