Feat v0.3.3 public entry + background jobs
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 20s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-sqlite (pull_request) Successful in 2m39s
CI/CD / test-go-pg (pull_request) Failing after 2m54s
CI/CD / build-and-deploy (pull_request) Has been skipped
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 20s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-sqlite (pull_request) Successful in 2m39s
CI/CD / test-go-pg (pull_request) Failing after 2m54s
CI/CD / build-and-deploy (pull_request) Has been skipped
Public workflow entry: unauthenticated routes at /api/v1/public/workflows/ for anonymous workflow participation. StartPublic creates instances with public:<uuid> identity, ResumePublic/AdvancePublic use entry tokens. Audience-gated: only public stages can be advanced anonymously. SLA scanner: background goroutine (5-min interval) checks active instances against per-stage sla_seconds. Fires workflow.sla_breach event on first breach, marks sla_breached in instance metadata (idempotent). Staleness sweep: new staleness_timeout_hours column on workflows. Scanner marks idle instances as stale, cancels open assignments, fires workflow.stale event. New store methods: ListActiveInstances, MarkInstanceStale. New events: workflow.sla_breach, workflow.stale. 3 new store tests (17 total), all passing on SQLite. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,12 +20,13 @@ func (s *WorkflowStore) Create(ctx context.Context, w *models.Workflow) error {
|
||||
branding := jsonOrEmpty(w.Branding)
|
||||
retention := jsonOrDefault(w.Retention, `{"mode":"archive"}`)
|
||||
return DB.QueryRowContext(ctx, `
|
||||
INSERT INTO workflows (team_id, name, slug, description, branding, entry_mode, is_active, on_complete, retention, webhook_url, webhook_secret, created_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
||||
INSERT INTO workflows (team_id, name, slug, description, branding, entry_mode, is_active,
|
||||
on_complete, retention, webhook_url, webhook_secret, staleness_timeout_hours, created_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
||||
RETURNING id, version, created_at, updated_at`,
|
||||
w.TeamID, w.Name, w.Slug, w.Description, branding, w.EntryMode,
|
||||
w.IsActive, jsonOrNull(w.OnComplete), retention,
|
||||
nullIfEmpty(w.WebhookURL), nullIfEmpty(w.WebhookSecret), w.CreatedBy,
|
||||
nullIfEmpty(w.WebhookURL), nullIfEmpty(w.WebhookSecret), w.StalenessTimeoutHours, w.CreatedBy,
|
||||
).Scan(&w.ID, &w.Version, &w.CreatedAt, &w.UpdatedAt)
|
||||
}
|
||||
|
||||
@@ -36,11 +37,11 @@ func (s *WorkflowStore) GetByID(ctx context.Context, id string) (*models.Workflo
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT id, team_id, name, slug, description, branding, entry_mode, is_active,
|
||||
version, on_complete, retention, webhook_url, webhook_secret,
|
||||
created_by, created_at, updated_at
|
||||
staleness_timeout_hours, created_by, created_at, updated_at
|
||||
FROM workflows WHERE id = $1`, id,
|
||||
).Scan(&w.ID, &w.TeamID, &w.Name, &w.Slug, &w.Description, &branding,
|
||||
&w.EntryMode, &w.IsActive, &w.Version, &onComplete, &retention,
|
||||
&webhookURL, &webhookSecret,
|
||||
&webhookURL, &webhookSecret, &w.StalenessTimeoutHours,
|
||||
&w.CreatedBy, &w.CreatedAt, &w.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -63,13 +64,13 @@ func (s *WorkflowStore) GetBySlug(ctx context.Context, teamID *string, slug stri
|
||||
if teamID != nil {
|
||||
q = `SELECT id, team_id, name, slug, description, branding, entry_mode, is_active,
|
||||
version, on_complete, retention, webhook_url, webhook_secret,
|
||||
created_by, created_at, updated_at
|
||||
staleness_timeout_hours, created_by, created_at, updated_at
|
||||
FROM workflows WHERE team_id = $1 AND slug = $2`
|
||||
args = []interface{}{*teamID, slug}
|
||||
} else {
|
||||
q = `SELECT id, team_id, name, slug, description, branding, entry_mode, is_active,
|
||||
version, on_complete, retention, webhook_url, webhook_secret,
|
||||
created_by, created_at, updated_at
|
||||
staleness_timeout_hours, created_by, created_at, updated_at
|
||||
FROM workflows WHERE team_id IS NULL AND slug = $1`
|
||||
args = []interface{}{slug}
|
||||
}
|
||||
@@ -79,7 +80,7 @@ func (s *WorkflowStore) GetBySlug(ctx context.Context, teamID *string, slug stri
|
||||
err := DB.QueryRowContext(ctx, q, args...).Scan(
|
||||
&w.ID, &w.TeamID, &w.Name, &w.Slug, &w.Description, &branding,
|
||||
&w.EntryMode, &w.IsActive, &w.Version, &onComplete, &retention,
|
||||
&webhookURL, &webhookSecret,
|
||||
&webhookURL, &webhookSecret, &w.StalenessTimeoutHours,
|
||||
&w.CreatedBy, &w.CreatedAt, &w.UpdatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -135,6 +136,9 @@ func (s *WorkflowStore) Update(ctx context.Context, id string, patch models.Work
|
||||
if patch.WebhookSecret != nil {
|
||||
add("webhook_secret", *patch.WebhookSecret)
|
||||
}
|
||||
if patch.StalenessTimeoutHours != nil {
|
||||
add("staleness_timeout_hours", *patch.StalenessTimeoutHours)
|
||||
}
|
||||
|
||||
if len(sets) == 0 {
|
||||
return nil
|
||||
@@ -166,7 +170,7 @@ func (s *WorkflowStore) ListForTeam(ctx context.Context, teamID string) ([]model
|
||||
return s.queryWorkflows(ctx, `
|
||||
SELECT id, team_id, name, slug, description, branding, entry_mode, is_active,
|
||||
version, on_complete, retention, webhook_url, webhook_secret,
|
||||
created_by, created_at, updated_at
|
||||
staleness_timeout_hours, created_by, created_at, updated_at
|
||||
FROM workflows WHERE team_id = $1
|
||||
ORDER BY name ASC`, teamID)
|
||||
}
|
||||
@@ -175,7 +179,7 @@ func (s *WorkflowStore) ListGlobal(ctx context.Context) ([]models.Workflow, erro
|
||||
return s.queryWorkflows(ctx, `
|
||||
SELECT id, team_id, name, slug, description, branding, entry_mode, is_active,
|
||||
version, on_complete, retention, webhook_url, webhook_secret,
|
||||
created_by, created_at, updated_at
|
||||
staleness_timeout_hours, created_by, created_at, updated_at
|
||||
FROM workflows WHERE team_id IS NULL
|
||||
ORDER BY name ASC`)
|
||||
}
|
||||
@@ -193,7 +197,7 @@ func (s *WorkflowStore) queryWorkflows(ctx context.Context, q string, args ...in
|
||||
var webhookURL, webhookSecret *string
|
||||
if err := rows.Scan(&w.ID, &w.TeamID, &w.Name, &w.Slug, &w.Description,
|
||||
&branding, &w.EntryMode, &w.IsActive, &w.Version, &onComplete,
|
||||
&retention, &webhookURL, &webhookSecret,
|
||||
&retention, &webhookURL, &webhookSecret, &w.StalenessTimeoutHours,
|
||||
&w.CreatedBy, &w.CreatedAt, &w.UpdatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -533,6 +537,40 @@ func (s *WorkflowStore) CancelInstance(ctx context.Context, id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *WorkflowStore) MarkInstanceStale(ctx context.Context, id string) error {
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
UPDATE workflow_instances SET status = 'stale' WHERE id = $1 AND status = 'active'`, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *WorkflowStore) ListActiveInstances(ctx context.Context) ([]models.WorkflowInstance, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT id, workflow_id, workflow_version, current_stage, stage_data,
|
||||
status, started_by, entry_token, metadata,
|
||||
stage_entered_at, created_at, updated_at
|
||||
FROM workflow_instances WHERE status = 'active'
|
||||
ORDER BY stage_entered_at ASC`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var result []models.WorkflowInstance
|
||||
for rows.Next() {
|
||||
var inst models.WorkflowInstance
|
||||
var stageData, metadata []byte
|
||||
if err := rows.Scan(&inst.ID, &inst.WorkflowID, &inst.WorkflowVersion,
|
||||
&inst.CurrentStage, &stageData, &inst.Status, &inst.StartedBy,
|
||||
&inst.EntryToken, &metadata,
|
||||
&inst.StageEnteredAt, &inst.CreatedAt, &inst.UpdatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
inst.StageData = stageData
|
||||
inst.Metadata = metadata
|
||||
result = append(result, inst)
|
||||
}
|
||||
return result, rows.Err()
|
||||
}
|
||||
|
||||
// ── Assignments (v0.3.1) ────────────────────
|
||||
|
||||
func (s *WorkflowStore) CreateAssignment(ctx context.Context, a *models.WorkflowAssignment) error {
|
||||
|
||||
Reference in New Issue
Block a user