Events and cron
Event bus
Package: sumeru/core/event
In-process pub/sub for cross-module automation.
event.Subscribe("record.updated", func(ctx context.Context, ev event.Event) error {
// ev.Payload["model"], ev.Payload["id"], ev.Payload["values"], …
return nil
})
| Field | Meaning |
|---|---|
Name | Event name (e.g. record.created, record.updated, cron.tick) |
Payload | Model name, record id, changed values, etc. |
Actor | User id when applicable |
ORM emits record.created and record.updated after successful commit (core/orm/crud_sideeffects.go).
Prefer runtime.Runtime for new code that publishes events in tests.
Transactional outbox
Package: sumeru/core/orm
CRUD mutations enqueue rows in sys.outbox.event in the same transaction. A background drain worker started from core/server/run.go (5s ticker) publishes pending events in batches of 100, marks them published, and publishes to the in-process queue (core/queue) for async consumers.
Use outbox events when downstream handlers must not run if the mutation rolls back.
Scheduler
Package: sumeru/core/scheduler
Started from core/server/run.go with a 1-minute default ticker.
- Selects due active
sys.cronrows inside a transaction withFOR UPDATE SKIP LOCKED(safe for multiple Sumeru instances) - Publishes
cron.tickwith cron metadata - Publishes optional custom
event_namefrom the cron row - When
sys.cron.codematches a handler registered viaRegisterCronHandler, runs that Go function - Updates
next_callandlast_callin the same transaction
scheduler.RegisterCronHandler("my_module.nightly_digest", func(ctx context.Context, payload map[string]interface{}) error {
// payload includes cron row fields
return nil
})
There is no Python/safe_eval — cron code must match a registered Go handler or serve as a lookup key only. CRM’s event.Subscribe("crm.cron_assign_leads") is not backed by a bundled sys.cron row; use Assign Leads on the team form, or seed your own cron if you need a schedule.
See Multi-instance cron for operational guidelines when running N replicas.
Automation addon
Path: sumeru/addons/automation/
Models:
| Model | Purpose |
|---|---|
sys.cron | Scheduled jobs |
sys.server.action | Event-triggered actions |
sys.workflow.transition | Workflow transitions (data model) |
The automation subscriber listens to record.created, record.updated, and cron.tick. It matches active sys.server.action rows by event_name (and optional model filter), then executes declarative code:
| Code prefix | Effect |
|---|---|
publish: | Republish with the trigger event payload |
write: | ORM write on payload model/id (ACL bypass) |
Unknown prefixes are logged at debug and skipped. See Events & automation for XML examples.
Example: business addon pattern
See sumeru_addons/sale_crm/init.go — subscribes to record.updated on crm.lead, creates a draft quotation when stage is Won.
See Events and hooks for addon conventions.