Documentation
¶
Overview ¶
Package workflows provides the WorkflowScheduler for cron-based session automation.
Index ¶
- func DefaultModelFamilies() map[string]string
- func LoadModelFamilyOverride(configPath string) (map[string]string, error)
- func ResolveModel(families map[string]string, model string) (string, error)
- func RunRetentionSweep(ctx context.Context, entClient *ent.Client, ...)
- func StartRetentionEnforcer(ctx context.Context, entClient *ent.Client, ...)
- func ValidateCronExpression(expr string) error
- func ValidateModel(model string) error
- type Scheduler
- func (s *Scheduler) FireNow(ctx context.Context, wf *ent.Workflow, arg string) (string, error)
- func (s *Scheduler) Reload(ctx context.Context, wf *ent.Workflow) error
- func (s *Scheduler) Remove(workflowID string) error
- func (s *Scheduler) SetModelFamilies(families map[string]string)
- func (s *Scheduler) Start(ctx context.Context)
- func (s *Scheduler) Stop()
- type SessionServiceInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultModelFamilies ¶ added in v1.42.0
DefaultModelFamilies returns the hardcoded family alias → concrete model ID map, e.g. "sonnet" → "claude-sonnet-4-6". Keep in sync with the frontend's MODEL_FAMILIES (web-app/src/lib/constants/programs.ts) so every alias the UI offers actually resolves.
func LoadModelFamilyOverride ¶ added in v1.42.0
LoadModelFamilyOverride loads family→model overrides from a JSON file and merges them over DefaultModelFamilies(), mirroring session/tokens/pricing.go's LoadPricingOverride. This is what lets a new Anthropic model version become a family's "latest" without a frontend (or even backend) redeploy — only the override file needs to change.
func ResolveModel ¶ added in v1.42.0
ResolveModel resolves a workflow's stored Model value to a concrete model ID using families. Values without the "family:" prefix (including "") pass through unchanged. An unknown or retired family alias returns an error rather than passing the broken "family:xxx" string through to the CLI.
Decision record (client vs. server-side family resolution): resolution happens here, server-side, at fire-time — not client-side at save-time — so that updating a family's "latest" model only requires editing this package's override file (LoadModelFamilyOverride), with no frontend redeploy needed to pick it up. It also means every fire (manual RunWorkflow and cron) always resolves against the current map, and a workflow that already stores a concrete model ID (pre-dating this feature) is never touched — ResolveModel is a no-op for any value without the "family:" prefix.
func RunRetentionSweep ¶
func RunRetentionSweep(ctx context.Context, entClient *ent.Client, workflowRepo session.WorkflowRepository)
RunRetentionSweep performs a single retention sweep. Exported for use in tests.
func StartRetentionEnforcer ¶
func StartRetentionEnforcer( ctx context.Context, entClient *ent.Client, workflowRepo session.WorkflowRepository, interval time.Duration, )
StartRetentionEnforcer starts a background goroutine that periodically archives completed workflow sessions according to per-workflow retention settings:
- archive_after_hours > 0: archive completed sessions that stopped more than N hours ago (requires maybeAutoArchive to be suppressed for these workflows)
- keep_sessions > 0: keep only the N most recent completed sessions, archiving older ones
Guards:
- Never archives sessions with status Active (1), Creating (0), or Paused (2)
- archive_after_hours == 0 means disabled (skip time-based archival for that workflow)
- keep_sessions == 0 means disabled (keep all sessions)
The goroutine exits when ctx is cancelled.
func ValidateCronExpression ¶
ValidateCronExpression validates a 5-field cron expression. Exported so workflow_service.go can use it without importing the cron library directly.
func ValidateModel ¶ added in v1.42.0
ValidateModel validates a workflow's Model field at save time (CreateWorkflow/ UpdateWorkflow), so a malformed value is rejected up front instead of silently breaking workflow launch later at fire time. Empty is always valid (means "use the program's default model").
Types ¶
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages cron-based workflow execution.
func NewScheduler ¶
func NewScheduler(repo session.WorkflowRepository, sessionSvc SessionServiceInterface, eventBus *events.EventBus) *Scheduler
NewScheduler creates a new WorkflowScheduler.
func (*Scheduler) FireNow ¶
FireNow immediately fires a workflow outside of cron schedule. Returns the created session ID. Used by RunWorkflow RPC and internal cron trigger.
func (*Scheduler) Reload ¶
Reload registers or re-registers a workflow's cron job. Called after create/update. If cron_enabled is false, removes any existing entry.
func (*Scheduler) Remove ¶
Remove removes a workflow's cron job by workflow ID string. Safe to call when no entry exists (no-op).
func (*Scheduler) SetModelFamilies ¶ added in v1.42.0
SetModelFamilies replaces the family alias → concrete model ID map used to resolve a workflow's Model field at fire time. Wired at startup from LoadModelFamilyOverride when an override file is present (see server/dependencies.go); falls back to DefaultModelFamilies() otherwise.
type SessionServiceInterface ¶
type SessionServiceInterface interface {
CreateSession(ctx context.Context, req *connect.Request[sessionv1.CreateSessionRequest]) (*connect.Response[sessionv1.CreateSessionResponse], error)
}
SessionServiceInterface is the minimal interface the scheduler needs from SessionService. Defined here to avoid a circular import: server/workflows does not import server/services.