Cron

Functions

Public API reference for the Cron extension

Extension Entry Points

FunctionDescription
NewExtension(opts ...ConfigOption) forge.ExtensionCreate the cron extension with functional options
NewExtensionWithConfig(config Config) forge.ExtensionCreate with a complete config
DefaultConfig() ConfigReturns the default configuration

Extension Accessors

MethodDescription
GetScheduler() SchedulerAccess the scheduler
GetRegistry() *JobRegistryAccess the job registry
GetExecutor() *ExecutorAccess the job executor
GetStorage() StorageAccess the storage backend
GetStats(ctx) (*SchedulerStats, error)Get scheduler statistics

Job Management

MethodDescription
CreateJob(ctx, job) errorCreate and schedule a new job
UpdateJob(ctx, jobID, update) errorUpdate a job's schedule or config
DeleteJob(ctx, jobID) errorDelete a job
TriggerJob(ctx, jobID) errorManually trigger a job execution

Scheduler Interface

MethodDescription
Start(ctx) errorStart the scheduler
Stop(ctx) errorStop the scheduler
IsRunning() boolCheck if the scheduler is running
IsLeader() boolCheck if this node is the leader (distributed mode)
AddJob(ctx, job) errorAdd a job to the scheduler
RemoveJob(ctx, jobID) errorRemove a job
UpdateJob(ctx, jobID, update) errorUpdate a job
ListJobs(ctx) ([]*Job, error)List all jobs
GetJob(ctx, jobID) (*Job, error)Get a job by ID
TriggerJob(ctx, jobID) errorTrigger immediate execution

Storage Interface

MethodDescription
Connect(ctx) errorConnect to the storage backend
Disconnect(ctx) errorDisconnect
Ping(ctx) errorHealth check
AcquireLock(ctx, lockID, ttl) (bool, error)Acquire a distributed lock
ReleaseLock(ctx, lockID) errorRelease a distributed lock
RefreshLock(ctx, lockID, ttl) errorExtend lock TTL

Admin API Endpoints

When EnableAPI is true:

MethodPathDescription
GET/api/cron/jobsList all jobs
POST/api/cron/jobsCreate a job
GET/api/cron/jobs/:idGet a job
PUT/api/cron/jobs/:idUpdate a job
DELETE/api/cron/jobs/:idDelete a job
POST/api/cron/jobs/:id/triggerTrigger a job
GET/api/cron/statsGet scheduler stats

How is this guide?

On this page