public async Task Handle(ScheduleTemporalBookmark message) { var bookmark = message.Bookmark; var bookmarkTypeName = bookmark.ModelType; var bookmarkType = Type.GetType(bookmarkTypeName) !; var model = _bookmarkSerializer.Deserialize(bookmark.Model, bookmarkType); _logger.LogDebug("Scheduling bookmark {@Bookmark}", model); switch (model) { case TimerBookmark timerBookmark: await _workflowInstanceScheduler.ScheduleAsync(bookmark.WorkflowInstanceId, bookmark.ActivityId, timerBookmark.ExecuteAt, null); break; case StartAtBookmark startAtBookmark: await _workflowInstanceScheduler.ScheduleAsync(bookmark.WorkflowInstanceId, bookmark.ActivityId, startAtBookmark.ExecuteAt, null); break; case CronBookmark cronBookmark: await _workflowInstanceScheduler.ScheduleAsync(bookmark.WorkflowInstanceId !, bookmark.ActivityId, cronBookmark.CronExpression); break; } }
public async Task Handle(BookmarkIndexingFinished notification, CancellationToken cancellationToken) { var bookmarks = notification.Bookmarks; var workflowInstanceId = notification.WorkflowInstanceId; var startAtBookmarks = bookmarks.FilterByType <StartAtBookmark>(); var timerBookmarks = bookmarks.FilterByType <TimerBookmark>(); var cronBookmarks = bookmarks.FilterByType <CronBookmark>(); await _workflowInstanceScheduler.UnscheduleAsync(workflowInstanceId, cancellationToken); foreach (var trigger in startAtBookmarks) { var bookmark = _bookmarkSerializer.Deserialize <StartAtBookmark>(trigger.Model); await Try(() => _workflowInstanceScheduler.ScheduleAsync(workflowInstanceId, trigger.ActivityId, bookmark.ExecuteAt, null, cancellationToken)); } foreach (var trigger in timerBookmarks) { var bookmark = _bookmarkSerializer.Deserialize <TimerBookmark>(trigger.Model); await Try(() => _workflowInstanceScheduler.ScheduleAsync(workflowInstanceId, trigger.ActivityId, bookmark.ExecuteAt, bookmark.Interval, cancellationToken)); } foreach (var trigger in cronBookmarks) { var bookmark = _bookmarkSerializer.Deserialize <CronBookmark>(trigger.Model); await Try(() => _workflowInstanceScheduler.ScheduleAsync(workflowInstanceId, trigger.ActivityId, bookmark.CronExpression, cancellationToken)); } }