cron

package
v0.0.1-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScheduleKindAt    = "at"
	ScheduleKindEvery = "every"
	ScheduleKindCron  = "cron"
)

Schedule kinds

View Source
const (
	SessionTargetMain     = "main"
	SessionTargetIsolated = "isolated"
)

Session targets

View Source
const (
	WakeModeNow           = "now"
	WakeModeNextHeartbeat = "next-heartbeat"
)

Wake modes

View Source
const (
	DeliveryModeAnnounce = "announce"
	DeliveryModeNone     = "none"
)

Delivery modes

View Source
const (
	PayloadKindSystemEvent = "systemEvent"
	PayloadKindAgentTurn   = "agentTurn"
)

Payload kinds

Variables

This section is empty.

Functions

This section is empty.

Types

type CronHandler

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

CronHandler manages the cron system

func NewCronHandler

func NewCronHandler(storePath string) *CronHandler

NewCronHandler creates a new cron handler

func (*CronHandler) AddJob

func (c *CronHandler) AddJob(job *Job) error

AddJob adds a new job

func (*CronHandler) GetJob

func (c *CronHandler) GetJob(id string) (*Job, bool)

GetJob returns a job by ID

func (*CronHandler) GetStatus

func (c *CronHandler) GetStatus() map[string]interface{}

GetStatus returns the cron status

func (*CronHandler) IsRunning

func (c *CronHandler) IsRunning() bool

IsRunning returns whether the cron is running

func (*CronHandler) ListJobs

func (c *CronHandler) ListJobs() []*Job

ListJobs returns all jobs

func (*CronHandler) RemoveJob

func (c *CronHandler) RemoveJob(id string) error

RemoveJob removes a job

func (*CronHandler) RunJob

func (c *CronHandler) RunJob(id string) error

RunJob immediately runs a job

func (*CronHandler) SetAgentTurnCallback

func (c *CronHandler) SetAgentTurnCallback(cb func(string, string, string) (string, error))

SetAgentTurnCallback sets the callback for agent turns

func (*CronHandler) SetBroadcastCallback

func (c *CronHandler) SetBroadcastCallback(cb func(string, string, string) error)

SetBroadcastCallback sets the callback for broadcasting

func (*CronHandler) SetSystemEventCallback

func (c *CronHandler) SetSystemEventCallback(cb func(string))

SetSystemEventCallback sets the callback for system events

func (*CronHandler) Start

func (c *CronHandler) Start()

Start starts the cron scheduler

func (*CronHandler) Stop

func (c *CronHandler) Stop()

Stop stops the cron scheduler

func (*CronHandler) UpdateJob

func (c *CronHandler) UpdateJob(id string, updates map[string]interface{}) (*Job, error)

UpdateJob updates a job

type Delivery

type Delivery struct {
	Mode       string `json:"mode"`              // "announce", "none"
	Channel    string `json:"channel,omitempty"` // "telegram", "discord", etc.
	To         string `json:"to,omitempty"`      // channel-specific target
	BestEffort bool   `json:"bestEffort"`
}

Delivery defines how to deliver job output

type Job

type Job struct {
	ID             string    `json:"id"`
	Name           string    `json:"name"`
	Description    string    `json:"description,omitempty"`
	AgentID        string    `json:"agentId,omitempty"` // specific agent or empty for default
	Enabled        bool      `json:"enabled"`
	Schedule       Schedule  `json:"schedule"`
	SessionTarget  string    `json:"sessionTarget"` // "main" or "isolated"
	WakeMode       string    `json:"wakeMode"`      // "now" or "next-heartbeat"
	Payload        Payload   `json:"payload"`
	Delivery       *Delivery `json:"delivery,omitempty"`
	DeleteAfterRun bool      `json:"deleteAfterRun"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
	// State
	State struct {
		NextRunAtMs       int64  `json:"nextRunAtMs"`
		LastRunAtMs       int64  `json:"lastRunAtMs"`
		LastStatus        string `json:"lastStatus"` // "ok", "error", "skipped"
		LastDurationMs    int64  `json:"lastDurationMs"`
		ConsecutiveErrors int    `json:"consecutiveErrors"`
	} `json:"state"`
}

Job represents a scheduled job

func CreateJobFromMap

func CreateJobFromMap(data map[string]interface{}) (*Job, error)

CreateJobFromMap creates a Job from a map (for API calls)

type JobStore

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

JobStore manages cron jobs

func NewJobStore

func NewJobStore(filePath string) *JobStore

NewJobStore creates a new job store

func (*JobStore) Add

func (js *JobStore) Add(job *Job) error

Add adds a new job

func (*JobStore) CalculateNextRun

func (js *JobStore) CalculateNextRun(job *Job) int64

CalculateNextRun calculates the next run time for a job

func (*JobStore) Get

func (js *JobStore) Get(id string) (*Job, bool)

Get returns a job by ID

func (*JobStore) GetDueJobs

func (js *JobStore) GetDueJobs() []*Job

GetDueJobs returns jobs that are due to run

func (*JobStore) List

func (js *JobStore) List() []*Job

List returns all jobs

func (*JobStore) Remove

func (js *JobStore) Remove(id string) error

Remove removes a job

func (*JobStore) Update

func (js *JobStore) Update(id string, updates map[string]interface{}) (*Job, error)

Update updates a job

type Payload

type Payload struct {
	Kind           string `json:"kind"`              // "systemEvent", "agentTurn"
	Text           string `json:"text,omitempty"`    // for systemEvent
	Message        string `json:"message,omitempty"` // for agentTurn
	Model          string `json:"model,omitempty"`
	Thinking       string `json:"thinking,omitempty"`
	TimeoutSeconds int    `json:"timeoutSeconds,omitempty"`
}

Payload defines what the job should do

type Schedule

type Schedule struct {
	Kind    string `json:"kind"`              // "at", "every", "cron"
	At      string `json:"at,omitempty"`      // ISO 8601 timestamp
	EveryMs int64  `json:"everyMs,omitempty"` // milliseconds
	Expr    string `json:"expr,omitempty"`    // cron expression
	Tz      string `json:"tz,omitempty"`      // timezone
}

Schedule defines when a job should run

Jump to

Keyboard shortcuts

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