Documentation
¶
Overview ¶
Package workflows provides the WorkflowScheduler for cron-based session automation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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).
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.