Triggers
A trigger publishes an empty CloudEvent (com.virtufin.api.trigger.fired) to its target topic
on a schedule: a 6-field cron expression or an @every duration, a due time (RFC 3339 or a
duration), with optional repeats and TTL. The Trigger service (Services)
wraps Dapr's Scheduler. Openspec:
item-identity,
standard-tags,
resource-groups.
What a trigger's values are for (property, config or tag) is explained once, in the WorkManager docs: Properties, config and tags.
Ids
| Rule | |
|---|---|
| Identity | A trigger is identified by its id alone. Every call names it by id; an id never changes. |
| Generated | ScheduleTrigger without an id generates a UUID of version 7 and answers it. |
| Given | A given id is a UUID of any version in its canonical form (lower-case, hyphenated, as every client writes it). Anything else fails with INVALID_ARGUMENT (INVALID_FIELD, field id). An id found again by rule is a UUID the caller derives (version 5: C# Ids.DerivedId, Python uuid.uuid5). |
| Never duplicated | A given id that exists fails with ALREADY_EXISTS (reason ID_EXISTS, resource the id) and changes nothing. There is no idempotent create. |
| Job name | The id is the Dapr job's name. |
| Display name | The name tag. There is no name field. |
Tags
tags (map<string,string>) are for people, clients and scripts; a tag never changes what the
trigger does. Set them when scheduling, and change them with
UpdateTriggerTags{id, set, remove}: the keys in set are set and the keys in remove removed
in one atomic step (a key in both is INVALID_FIELD, field remove). Other keys, the groups,
the owner, the schedule and the next firing stay as they are. The standard keys (name,
managed-by, …) are defined in the naming fragments of worker-devkit (infra keys) and domain-devkit (domain keys); other keys are free-form.
Groups
groups is the set of group ids the trigger belongs to, given when scheduling and changed by
the WorkManager's group calls (groups are WorkManager records):
| Call | Answer | Notes |
|---|---|---|
AddTriggerToGroup{id, group} |
empty | Adding it again changes nothing. A group that does not exist fails with FAILED_PRECONDITION (GROUP_NOT_FOUND), one being deleted or a trigger marked deleting with DELETING. |
RemoveTriggerFromGroup{id, group, for_group_deletion} |
remaining_groups |
The groups it still belongs to. Only a group deletion deletes members: without for_group_deletion, removing the last group leaves the trigger in no group, running (empty answer), and it can join groups again. With for_group_deletion (the WorkManager's DeleteGroup), removing the last group marks the trigger deleting and answers empty; the caller then calls DeleteTrigger. The trigger keeps that last group until it is deleted, so a repeated group deletion finds it again; repeating the removal answers empty again. A group the trigger is not in fails with FAILED_PRECONDITION (NOT_MEMBER) either way. |
ListTriggers{group} |
the members |
Membership changes are compare-and-swaps on the trigger's metadata record, so two concurrent changes never lose each other, and of two concurrent removals of a trigger's last two groups exactly one sees the empty set.
Every group named in ScheduleTrigger.groups or AddTriggerToGroup must exist: the gateway
asks the WorkManager (GetGroup, through its own route to the backends). A group that does
not exist fails with FAILED_PRECONDITION (GROUP_NOT_FOUND), a group being deleted with
DELETING, and a WorkManager that does not answer with UNAVAILABLE; nothing is changed then.
Owner
owner_worker_id names the worker a trigger exists for. When the WorkManager deletes that
worker it deletes the trigger too, unless the trigger belongs to a group: then it only clears
the owner with ClearTriggerOwner{id}, which does not reschedule the trigger.
Listing
ListTriggers{owner_worker_id?, tag_filters, group?} answers the triggers matching every given
filter (tag_filters: exact TagFilter{key, value} matches, all of which must hold).
Storage
| What | Where |
|---|---|
| Schedule, due time, repeats, TTL, target topic | the Dapr job (its data: {target_topic, schedule_token, firings}; firings only when finite) |
| Tags, groups, owner | a metadata record in the gateway's state store, sys.api.trigger.metadata.<trigger id> |
| Every record's trigger id | the index sys.api.trigger.metadata.index (id → when it was added) |
The record is keyed by the trigger id itself. The record is written
before the job is scheduled and deleted after the job, and changing it never touches the
job. ListTriggers and GetTrigger join the two:
- a record whose job is gone (a trigger that ran out, a create that failed) is never shown;
- a job without a record shows without tags, groups or owner.
A record without a job that is younger than one minute counts as a create in flight
(ID_EXISTS); an older one is taken over by the next create of that id.
Records do not outlive their triggers:
- Last firing. A trigger that fires a finite number of times (a due time without a
schedule fires once; a schedule with
repeatsfires that often) counts its firings in the record; its last firing deletes the record and publishessys.api.trigger.deleted. A trigger that fires until deleted costs no write per firing. - Everything else (a TTL that ran out, which has no callback; a last firing whose cleanup
failed; a create or delete that crashed half way):
ListTriggersdeletes every indexed record whose job is gone and that is older than one minute.
Events
sys.api.trigger.scheduled (com.virtufin.api.trigger.scheduled) carries the trigger's
definition (id, schedule, due_time, repeats, ttl, target_topic, owner_worker_id,
tags, groups). It is published when a trigger is scheduled, and again whenever its tags,
groups or owner change. sys.api.trigger.deleted carries id. Both are best effort; see
Events.
Errors
See Errors. GetTrigger, DeleteTrigger and the membership calls on a trigger
that does not exist fail with NOT_FOUND; a scheduler failure is UNAVAILABLE.