async Task <WorkflowProcessingResult> IWorkflowEngine.ProcessEvent(Guid workflowId, IEvent @event, CancellationToken cancellationToken) { var started = DateTime.UtcNow; var stopwatch = Stopwatch.StartNew(); WorkflowProcessingResult workflowProcessingResult = null; try { workflowProcessingResult = await ProcessEventInternal(workflowId, @event, cancellationToken).ConfigureAwait(false); return(workflowProcessingResult); } finally { stopwatch.Stop(); Log.Debug("Finished execution of an event=[{code}] {duration}, {workflowInstanceId}", @event.Code, stopwatch.Elapsed, workflowProcessingResult?.WorkflowInstance?.Id); if (null != workflowProcessingResult?.WorkflowInstance) { // 1. save workflow event execution log into store var workflowInstanceEventLog = new WorkflowInstanceEventLog(workflowProcessingResult.WorkflowInstance.Id, @event.Code, started, (int)stopwatch.ElapsedMilliseconds); await WorkflowEngineBuilder.WorkflowStore.SaveWorkflowInstanceEventLog(workflowInstanceEventLog, cancellationToken).ConfigureAwait(false); // 2. make sure that workflow instance lock is removed for non hierarchical events if (!(@event is IHierarchicalEvent)) { await UnlockWorkflowInstance(workflowProcessingResult.WorkflowInstance, cancellationToken).ConfigureAwait(false); } } } }
async Task <WorkflowProcessingResult> IWorkflowEngine.ProcessMessage(IWorkflowMessage workflowMessage, CancellationToken cancellationToken) { var started = DateTime.UtcNow; var stopwatch = Stopwatch.StartNew(); WorkflowProcessingResult workflowProcessingResult = null; try { switch (workflowMessage) { case IEventRequestWorkflowMessage eventWorkflowMessage: workflowProcessingResult = await ProcessMessageInternal(eventWorkflowMessage, cancellationToken).ConfigureAwait(false); break; case IAsynchronousTransitionWorkflowMessage asynchronousTransitionWorkflowMessage: workflowProcessingResult = await ProcessMessageInternal(asynchronousTransitionWorkflowMessage, cancellationToken).ConfigureAwait(false); break; case IDelayedTransitionWorkflowMessage delayedTransitionWorkflowMessage: workflowProcessingResult = await ProcessMessageInternal(delayedTransitionWorkflowMessage, cancellationToken).ConfigureAwait(false); break; default: workflowProcessingResult = await ProcessMessageInternal(workflowMessage, cancellationToken).ConfigureAwait(false); break; } return(workflowProcessingResult); } finally { stopwatch.Stop(); if (Log.IsEnabled(LogEventLevel.Verbose)) { Log.Verbose("Finished processing of a {messageID}, {duration}, {workflowInstanceId}", workflowMessage.WorkflowMessageId, stopwatch.Elapsed, workflowProcessingResult?.WorkflowInstance?.Id); } if (null != workflowProcessingResult?.WorkflowInstance) { // 1. save workflow message execution log into store var workflowInstanceMessageLog = new WorkflowInstanceMessageLog(workflowProcessingResult.WorkflowInstance.Id, workflowMessage.WorkflowMessageId, workflowMessage.GetType().Name, started, (int)stopwatch.ElapsedMilliseconds); await WorkflowEngineBuilder.WorkflowStore.SaveWorkflowInstanceMessageLog(workflowInstanceMessageLog, cancellationToken).ConfigureAwait(false); // 2. make sure that workflow instance lock is removed if (workflowProcessingResult.WorkflowInstance.Lock.LockedAt < workflowProcessingResult.WorkflowInstance.Lock.LockedUntil) { await UnlockWorkflowInstance(workflowProcessingResult.WorkflowInstance, cancellationToken).ConfigureAwait(false); } } } }