cron

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentRunner

type AgentRunner interface {
	Run(ctx context.Context, sessionKey string, prompt string) (string, error)
}

AgentRunner is the interface for executing agent turns. This avoids import cycles -- wiring.go will provide the concrete implementation.

type ChannelSender

type ChannelSender interface {
	SendMessage(ctx context.Context, channel string, message string) error
}

ChannelSender sends a message to a specific channel. This avoids import cycles -- wiring.go will provide the concrete implementation.

type Delivery

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

Delivery handles dispatching job results to configured channels.

func NewDelivery

func NewDelivery(sender ChannelSender, typing TypingIndicator, logger *zap.SugaredLogger) *Delivery

NewDelivery creates a new Delivery instance. If sender is nil, delivery will be a no-op (results are only stored in history).

func (*Delivery) Deliver

func (d *Delivery) Deliver(ctx context.Context, result *JobResult, targets []string) error

Deliver sends a job result to the specified target channels.

func (*Delivery) DeliverStart

func (d *Delivery) DeliverStart(ctx context.Context, jobName string, targets []string)

DeliverStart sends a notification that a cron job has started execution.

func (*Delivery) StartTyping

func (d *Delivery) StartTyping(ctx context.Context, targets []string) func()

StartTyping starts a typing indicator on all target channels. The returned stop function ends all typing indicators. It is always non-nil.

type EntStore

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

EntStore implements Store using the Ent ORM client.

func NewEntStore

func NewEntStore(client *ent.Client) *EntStore

NewEntStore creates a new EntStore backed by the given Ent client.

func (*EntStore) Create

func (s *EntStore) Create(ctx context.Context, job Job) error

Create persists a new cron job.

func (*EntStore) Delete

func (s *EntStore) Delete(ctx context.Context, id string) error

Delete removes a cron job by ID.

func (*EntStore) Get

func (s *EntStore) Get(ctx context.Context, id string) (*Job, error)

Get retrieves a cron job by ID.

func (*EntStore) GetByName

func (s *EntStore) GetByName(ctx context.Context, name string) (*Job, error)

GetByName retrieves a cron job by its unique name.

func (*EntStore) List

func (s *EntStore) List(ctx context.Context) ([]Job, error)

List returns all cron jobs.

func (*EntStore) ListAllHistory

func (s *EntStore) ListAllHistory(ctx context.Context, limit int) ([]HistoryEntry, error)

ListAllHistory returns execution history across all jobs, ordered by most recent first.

func (*EntStore) ListEnabled

func (s *EntStore) ListEnabled(ctx context.Context) ([]Job, error)

ListEnabled returns only enabled cron jobs.

func (*EntStore) ListHistory

func (s *EntStore) ListHistory(ctx context.Context, jobID string, limit int) ([]HistoryEntry, error)

ListHistory returns execution history for a specific job, ordered by most recent first.

func (*EntStore) SaveHistory

func (s *EntStore) SaveHistory(ctx context.Context, entry HistoryEntry) error

SaveHistory persists a job execution history entry.

func (*EntStore) Update

func (s *EntStore) Update(ctx context.Context, job Job) error

Update modifies an existing cron job.

type Executor

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

Executor runs cron jobs by delegating to an AgentRunner and persisting results.

func NewExecutor

func NewExecutor(runner AgentRunner, delivery *Delivery, store Store, logger *zap.SugaredLogger) *Executor

NewExecutor creates a new Executor.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, job Job) *JobResult

Execute runs a single cron job and returns the result. It persists the execution history and delivers results to configured channels.

type HistoryEntry

type HistoryEntry struct {
	ID           string
	JobID        string
	JobName      string
	Status       string // "running" | "completed" | "failed"
	Prompt       string
	Result       string
	ErrorMessage string
	TokensUsed   int
	StartedAt    time.Time
	CompletedAt  *time.Time
}

HistoryEntry represents a persisted execution record for a cron job.

type Job

type Job struct {
	ID           string
	Name         string
	ScheduleType string // "at" | "every" | "cron"
	Schedule     string
	Prompt       string
	SessionMode  string // "isolated" | "main"
	DeliverTo    []string
	Timezone     string
	Enabled      bool
	LastRunAt    *time.Time
	NextRunAt    *time.Time
	CreatedAt    time.Time
}

Job represents a scheduled cron job in the domain layer.

type JobResult

type JobResult struct {
	JobID     string
	JobName   string
	Response  string
	Error     error
	StartedAt time.Time
	Duration  time.Duration
}

JobResult holds the outcome of a single job execution.

type Scheduler

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

Scheduler manages cron job registration, lifecycle, and concurrent execution.

func New

func New(store Store, executor *Executor, timezone string, maxJobs int, logger *zap.SugaredLogger) *Scheduler

New creates a new Scheduler.

func (*Scheduler) AddJob

func (s *Scheduler) AddJob(ctx context.Context, job Job) error

AddJob creates a new job in the store and registers it with the scheduler.

func (*Scheduler) AllHistory

func (s *Scheduler) AllHistory(ctx context.Context, limit int) ([]HistoryEntry, error)

AllHistory returns execution history across all jobs.

func (*Scheduler) History

func (s *Scheduler) History(ctx context.Context, jobID string, limit int) ([]HistoryEntry, error)

History returns execution history for a specific job.

func (*Scheduler) ListJobs

func (s *Scheduler) ListJobs(ctx context.Context) ([]Job, error)

ListJobs returns all cron jobs from the store.

func (*Scheduler) PauseJob

func (s *Scheduler) PauseJob(ctx context.Context, id string) error

PauseJob disables a job so it no longer fires.

func (*Scheduler) RemoveJob

func (s *Scheduler) RemoveJob(ctx context.Context, id string) error

RemoveJob removes a job from the scheduler and deletes it from the store.

func (*Scheduler) ResumeJob

func (s *Scheduler) ResumeJob(ctx context.Context, id string) error

ResumeJob re-enables a paused job and registers it with the scheduler.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context) error

Start loads all enabled jobs from the database, registers them with the cron scheduler, and starts the scheduler. The provided context is used for the initial load; the scheduler itself runs until Stop is called.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop gracefully shuts down the scheduler and waits for running jobs to drain.

type Store

type Store interface {
	Create(ctx context.Context, job Job) error
	Get(ctx context.Context, id string) (*Job, error)
	GetByName(ctx context.Context, name string) (*Job, error)
	List(ctx context.Context) ([]Job, error)
	ListEnabled(ctx context.Context) ([]Job, error)
	Update(ctx context.Context, job Job) error
	Delete(ctx context.Context, id string) error
	SaveHistory(ctx context.Context, entry HistoryEntry) error
	ListHistory(ctx context.Context, jobID string, limit int) ([]HistoryEntry, error)
	ListAllHistory(ctx context.Context, limit int) ([]HistoryEntry, error)
}

Store defines the persistence interface for cron jobs and their history.

type TypingIndicator

type TypingIndicator interface {
	StartTyping(ctx context.Context, channel string) (stop func(), err error)
}

TypingIndicator starts a typing indicator on a channel.

Jump to

Keyboard shortcuts

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