Class TriggerService
The Trigger service (openspec item-identity, write-results, standard-tags Trigger Tags,
resource-groups): a trigger is a Dapr job named by the trigger's id, whose data holds the
target topic, plus a metadata record (TriggerMetadataStore) holding its tags,
groups and owner, so those change without rescheduling the job. The record is written
before the job is scheduled and deleted after the job; ListTriggers joins the two,
so a record whose job is gone is never shown and a job without a record shows untagged
and in no group.
public class TriggerService : Trigger.TriggerBase
- Inheritance
-
Trigger.TriggerBaseTriggerService
- Inherited Members
Constructors
TriggerService(DaprClient, DaprClient, DaprComponentOptions, ILogger<TriggerService>, TriggerMetadataStore, IGroupExistenceCheck, TopicCatalog?, TimeProvider?)
public TriggerService(Dapr.DaprClient dapr, DaprClient events, DaprComponentOptions components, ILogger<TriggerService> logger, TriggerMetadataStore metadata, IGroupExistenceCheck groups, TopicCatalog? topics = null, TimeProvider? time = null)
Parameters
daprDapr.DaprClientThe Jobs API (the scheduler).
eventsDaprClientPublishes the change events (TriggerScheduled, TriggerDeleted).
componentsDaprComponentOptionsloggerILogger<TriggerService>metadataTriggerMetadataStoreThe triggers' tags, groups and owners.
groupsIGroupExistenceCheckChecks that the groups a trigger is put into exist.
topicsTopicCatalogtimeTimeProvider
Fields
InFlightCreateGrace
How long a metadata record without a job counts as a create in flight. A create holds its record only for one Dapr ScheduleJob call (a scheduler stall of 9 s was seen on demo, api#53); a record older than this whose job does not exist is left over (a create or delete that crashed half way, or a job that ran out) and a create may take it over.
public static readonly TimeSpan InFlightCreateGrace
Field Value
Methods
AddTriggerToGroup(AddTriggerToGroupRequest, ServerCallContext)
For the WorkManager (group membership and owned-trigger cleanup): none of these reschedules the trigger, so its next firing stays. Adds the trigger to a group; adding it again changes nothing. A trigger being deleted (its last group removed) fails with FAILED_PRECONDITION (reason DELETING).
public override Task<AddTriggerToGroupResponse> AddTriggerToGroup(AddTriggerToGroupRequest request, ServerCallContext context)
Parameters
requestAddTriggerToGroupRequestThe request received from the client.
contextServerCallContextThe context of the server-side call handler being invoked.
Returns
- Task<AddTriggerToGroupResponse>
The response to send back to the client (wrapped by a task).
ClearTriggerOwner(ClearTriggerOwnerRequest, ServerCallContext)
Clears owner_worker_id (a grouped trigger outliving its owner worker).
public override Task<ClearTriggerOwnerResponse> ClearTriggerOwner(ClearTriggerOwnerRequest request, ServerCallContext context)
Parameters
requestClearTriggerOwnerRequestThe request received from the client.
contextServerCallContextThe context of the server-side call handler being invoked.
Returns
- Task<ClearTriggerOwnerResponse>
The response to send back to the client (wrapped by a task).
DeleteTrigger(DeleteTriggerRequest, ServerCallContext)
Deletes the trigger and its tags and groups. NOT_FOUND when there is none.
public override Task<DeleteTriggerResponse> DeleteTrigger(DeleteTriggerRequest request, ServerCallContext context)
Parameters
requestDeleteTriggerRequestThe request received from the client.
contextServerCallContextThe context of the server-side call handler being invoked.
Returns
- Task<DeleteTriggerResponse>
The response to send back to the client (wrapped by a task).
GetTrigger(GetTriggerRequest, ServerCallContext)
NOT_FOUND (reason NOT_FOUND) when there is no such trigger.
public override Task<GetTriggerResponse> GetTrigger(GetTriggerRequest request, ServerCallContext context)
Parameters
requestGetTriggerRequestThe request received from the client.
contextServerCallContextThe context of the server-side call handler being invoked.
Returns
- Task<GetTriggerResponse>
The response to send back to the client (wrapped by a task).
ListTriggers(ListTriggersRequest, ServerCallContext)
public override Task<ListTriggersResponse> ListTriggers(ListTriggersRequest request, ServerCallContext context)
Parameters
requestListTriggersRequestcontextServerCallContext
Returns
- Task<ListTriggersResponse>
OnFiredAsync(string, IReadOnlyDictionary<string, string>?, CancellationToken)
A job fired and its event was published (DaprAppCallbackService). Its last firing deletes the trigger's metadata record and announces the trigger deleted, since the scheduler drops the job by itself. A job that fires until deleted costs nothing here. Best effort: a failure is logged, and ListTriggers deletes what is left.
public Task OnFiredAsync(string id, IReadOnlyDictionary<string, string>? jobData, CancellationToken cancellationToken)
Parameters
idstringjobDataIReadOnlyDictionary<string, string>cancellationTokenCancellationToken
Returns
RemoveTriggerFromGroup(RemoveTriggerFromGroupRequest, ServerCallContext)
Removes the trigger from a group and answers the groups it still belongs to. Only a group deletion deletes members (for_group_deletion): when none remain then, the trigger is marked deleting (it keeps the group until it is deleted, so a repeated group deletion finds it again) and the caller deletes it with DeleteTrigger. Otherwise an empty answer means the trigger is now in no group, and it keeps running.
public override Task<RemoveTriggerFromGroupResponse> RemoveTriggerFromGroup(RemoveTriggerFromGroupRequest request, ServerCallContext context)
Parameters
requestRemoveTriggerFromGroupRequestThe request received from the client.
contextServerCallContextThe context of the server-side call handler being invoked.
Returns
- Task<RemoveTriggerFromGroupResponse>
The response to send back to the client (wrapped by a task).
ScheduleTrigger(ScheduleTriggerRequest, ServerCallContext)
Creates a trigger. A given id that exists fails with ALREADY_EXISTS (reason ID_EXISTS) and changes nothing.
public override Task<ScheduleTriggerResponse> ScheduleTrigger(ScheduleTriggerRequest request, ServerCallContext context)
Parameters
requestScheduleTriggerRequestThe request received from the client.
contextServerCallContextThe context of the server-side call handler being invoked.
Returns
- Task<ScheduleTriggerResponse>
The response to send back to the client (wrapped by a task).
UpdateTriggerTags(UpdateTriggerTagsRequest, ServerCallContext)
Sets the keys in set and removes the keys in remove in one atomic step.
The schedule, the next firing, the groups and the owner stay as they are.
public override Task<UpdateTriggerTagsResponse> UpdateTriggerTags(UpdateTriggerTagsRequest request, ServerCallContext context)
Parameters
requestUpdateTriggerTagsRequestThe request received from the client.
contextServerCallContextThe context of the server-side call handler being invoked.
Returns
- Task<UpdateTriggerTagsResponse>
The response to send back to the client (wrapped by a task).