All checks were successful
CI/CD / detect-changes (pull_request) Successful in 24s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-go-pg (pull_request) Successful in 2m30s
CI/CD / test-sqlite (pull_request) Successful in 2m37s
CI/CD / build-and-deploy (pull_request) Successful in 1m30s
Three trigger primitives replacing the old monolithic scheduler: - Event triggers: extensions subscribe to bus patterns via manifest, async handler invocation through sandbox.CallEntryPoint - Webhook triggers: inbound HTTP at /api/v1/hooks/:pkg/:slug with HMAC-SHA256 verification and synchronous Starlark response - Scheduled tasks: user-created cron scripts with restricted sandbox (no raw HTTP, no DB table creation), runs as creator identity New tables: triggers, scheduled_tasks, trigger_logs (postgres + sqlite). New permission: triggers.register. Full admin + user CRUD APIs. SyncManifestTriggers hooked into seed and install flows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"switchboard-core/models"
|
|
)
|
|
|
|
// TriggerStore manages extension-declared event and webhook triggers.
|
|
type TriggerStore interface {
|
|
// CRUD
|
|
Create(ctx context.Context, t *models.Trigger) error
|
|
GetByID(ctx context.Context, id string) (*models.Trigger, error)
|
|
Update(ctx context.Context, t *models.Trigger) error
|
|
Delete(ctx context.Context, id string) error
|
|
|
|
// Queries
|
|
List(ctx context.Context, opts TriggerListOptions) ([]models.Trigger, int, error)
|
|
ListByPackage(ctx context.Context, packageID string) ([]models.Trigger, error)
|
|
ListEnabledByType(ctx context.Context, triggerType string) ([]models.Trigger, error)
|
|
|
|
// Lifecycle
|
|
SetEnabled(ctx context.Context, id string, enabled bool) error
|
|
UpdateFireState(ctx context.Context, id string, lastFireAt time.Time, lastError string) error
|
|
|
|
// Webhook resolution
|
|
GetWebhook(ctx context.Context, packageID, slug string) (*models.Trigger, error)
|
|
|
|
// Cleanup
|
|
DeleteForPackage(ctx context.Context, packageID string) error
|
|
|
|
// Logs
|
|
LogExecution(ctx context.Context, log *models.TriggerLog) error
|
|
ListLogs(ctx context.Context, triggerID string, limit int) ([]models.TriggerLog, error)
|
|
PruneLogs(ctx context.Context, before time.Time) (int64, error)
|
|
}
|
|
|
|
// TriggerListOptions provides filtering for trigger list queries.
|
|
type TriggerListOptions struct {
|
|
ListOptions
|
|
PackageID string
|
|
Type string
|
|
Enabled *bool
|
|
}
|