Documentation
¶
Index ¶
- Constants
- func DecodePluginJob(job Job) (pluginID, key, runtimeName, description string, payload map[string]any, ...)
- func IsPluginJob(job Job) bool
- func SchedulerDefinition() tools.Definition
- type ChatFunc
- type Decision
- type HeartbeatConfig
- type Job
- type OnJobFunc
- type Schedule
- type SchedulerTool
- type Service
- func (s *Service) AddJob(name, message string, sched Schedule, sessionMode string) (Job, error)
- func (s *Service) AddOnJobListener(fn OnJobFunc)
- func (s *Service) AddPluginJob(pluginID, key, runtimeName, name, description string, sched Schedule, ...) (Job, error)
- func (s *Service) ListJobs() []Job
- func (s *Service) RemoveJob(id string) error
- func (s *Service) ScheduleEvery(ctx context.Context, every string, fn TaskFunc) error
- func (s *Service) SetHeartbeat(cfg HeartbeatConfig, chat ChatFunc, notifier notify.Notifier)
- func (s *Service) SetLegacyDataPath(path string)
- func (s *Service) SetOnJob(fn OnJobFunc)
- func (s *Service) SetUserJobsEnabled(enabled bool)
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) StartEphemeral(ctx context.Context) error
- func (s *Service) StartHeartbeat(ctx context.Context, every string) error
- func (s *Service) Stop() error
- type TaskFunc
Constants ¶
const ( // SessionReuse reuses the same session across job executions (default). SessionReuse = "reuse" // SessionNew creates a fresh session for each execution. SessionNew = "new" )
const ( JobOwnerUser = "user" JobOwnerPlugin = "plugin" )
Job is the persisted job definition.
Variables ¶
This section is empty.
Functions ¶
func DecodePluginJob ¶ added in v0.9.0
func DecodePluginJob(job Job) (pluginID, key, runtimeName, description string, payload map[string]any, ok bool)
DecodePluginJob decodes the legacy reserved-message plugin job envelope. It remains only for migration of pre-schema-hardening scheduler rows.
func IsPluginJob ¶ added in v0.9.0
func SchedulerDefinition ¶ added in v0.8.0
func SchedulerDefinition() tools.Definition
SchedulerDefinition returns the tool definition without requiring a live service.
Types ¶
type HeartbeatConfig ¶
HeartbeatConfig holds heartbeat-specific settings.
type Job ¶
type Job struct {
ID string `json:"id"`
OwnerKind string `json:"owner_kind,omitempty"`
PluginID string `json:"plugin_id,omitempty"`
JobKey string `json:"job_key,omitempty"`
RuntimeName string `json:"runtime_name,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Schedule Schedule `json:"schedule"`
Message string `json:"message,omitempty"`
Payload map[string]any `json:"payload,omitempty"`
SessionMode string `json:"session_mode"` // "reuse" (default) or "new"
Enabled bool `json:"enabled"`
AgentID string `json:"agent_id,omitempty"` // agent to route to (empty = default)
UserID int64 `json:"user_id,omitempty"` // user context (0 = none)
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
LastRunAt *time.Time `json:"last_run_at,omitempty"`
LastError string `json:"last_error,omitempty"`
}
type Schedule ¶
type Schedule struct {
Cron string `json:"cron,omitempty"` // "0 9 * * 1-5"
Every string `json:"every,omitempty"` // "30m", "2h"
At string `json:"at,omitempty"` // RFC3339: "2024-01-15T14:30:00+08:00"
}
Schedule defines when a job runs. Exactly one field must be set.
type SchedulerTool ¶
type SchedulerTool struct {
// contains filtered or unexported fields
}
SchedulerTool exposes scheduler management as an agent tool.
func NewTool ¶
func NewTool(service *Service) *SchedulerTool
NewTool creates a SchedulerTool backed by the given service.
func (*SchedulerTool) Definition ¶
func (t *SchedulerTool) Definition() tools.Definition
Definition returns the tool definition for the LLM.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages scheduled jobs backed by gocron/v2 with database persistence.
func New ¶
New creates a scheduler service backed by the given database. Call Start to load persisted jobs and begin scheduling.
func NewFromPath ¶
NewFromPath creates a scheduler service that opens its own SQLite database at the given path. The database is closed when Stop is called.
func (*Service) AddJob ¶
AddJob creates, persists, and schedules a new job. sessionMode controls session reuse: "reuse" (default) or "new".
func (*Service) AddOnJobListener ¶ added in v0.9.0
AddOnJobListener appends an additional callback invoked when a job fires.
func (*Service) AddPluginJob ¶ added in v0.9.0
func (s *Service) AddPluginJob(pluginID, key, runtimeName, name, description string, sched Schedule, payload map[string]any) (Job, error)
AddPluginJob creates, persists, and schedules a plugin-owned job.
func (*Service) ScheduleEvery ¶
ScheduleEvery registers a non-persisted recurring task on the existing scheduler.
func (*Service) SetHeartbeat ¶
func (s *Service) SetHeartbeat(cfg HeartbeatConfig, chat ChatFunc, notifier notify.Notifier)
SetHeartbeat configures the heartbeat on the scheduler service.
func (*Service) SetLegacyDataPath ¶
SetLegacyDataPath sets the directory where the legacy jobs.json file may exist. If set, Start will attempt a one-time migration from file to DB.
func (*Service) SetUserJobsEnabled ¶ added in v0.9.0
SetUserJobsEnabled controls whether persisted user-owned scheduler jobs are loaded.
func (*Service) StartEphemeral ¶
StartEphemeral starts the shared scheduler without loading persisted jobs. Use this when the scheduler is only needed for internal tasks such as heartbeat.
func (*Service) StartHeartbeat ¶
StartHeartbeat schedules the heartbeat poll on the shared scheduler.