feat: Function triggers — schedule, inbound hook, domain events

Migration 00016: function_id on scheduled_jobs/inbound_hooks,
event_pattern on functions, 'event' in the run-trigger enum.

- Jobs deliver to a function instead of HTTP when function_id is set;
  the run's status_code mirrors the process exit code. Clearing the
  field returns the job to URL delivery.
- Inbound hooks gain mode "function" — received body becomes stdin
  payload, acked immediately, run recorded async.
- event_pattern (document.*, *, exact type) fires the function detached
  on matching publishEvent — never blocks realtime/webhook fan-out.
- One executeFunction path serves manual/schedule/hook/event; run rows
  record the trigger source.
- Backend image now ships bun 1.3.14 so Functions work under compose.

Dashboard: job target picker, hook function mode, event-pattern field.

Verified live: job run → success (status_code 0), hook POST → run,
document.created → event run with correct payload.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Tomas DvorakandDevin committed 2026-09-24 20:28:04 +02:00
1 parent c094afad65
commit a84049b8fc
40 files changed
+716 -157

No files matched your search

@@ -0,0 +1,34 @@
-- +goose Up
ALTER TABLE core.scheduled_jobs
ADD COLUMN function_id UUID REFERENCES core.functions(id) ON DELETE SET NULL;
ALTER TABLE core.inbound_hooks
ADD COLUMN function_id UUID REFERENCES core.functions(id) ON DELETE CASCADE;
ALTER TABLE core.inbound_hooks
DROP CONSTRAINT inbound_hooks_mode_check;
ALTER TABLE core.inbound_hooks
ADD CONSTRAINT inbound_hooks_mode_check
CHECK (mode IN ('event','job','function'));
ALTER TABLE core.functions
ADD COLUMN event_pattern TEXT NOT NULL DEFAULT '';
ALTER TABLE core.function_runs
DROP CONSTRAINT function_runs_trigger_check;
ALTER TABLE core.function_runs
ADD CONSTRAINT function_runs_trigger_check
CHECK (trigger IN ('manual','schedule','hook','event'));
-- +goose Down
ALTER TABLE core.function_runs
DROP CONSTRAINT function_runs_trigger_check;
ALTER TABLE core.function_runs
ADD CONSTRAINT function_runs_trigger_check
CHECK (trigger IN ('manual','schedule','hook'));
ALTER TABLE core.functions DROP COLUMN IF EXISTS event_pattern;
ALTER TABLE core.inbound_hooks
DROP CONSTRAINT inbound_hooks_mode_check;
ALTER TABLE core.inbound_hooks
ADD CONSTRAINT inbound_hooks_mode_check CHECK (mode IN ('event','job'));
ALTER TABLE core.inbound_hooks DROP COLUMN IF EXISTS function_id;
ALTER TABLE core.scheduled_jobs DROP COLUMN IF EXISTS function_id;