Example #1
0
        private async Task <RunWorkflowResult> ResumeWorkflowAsync(WorkflowExecutionContext workflowExecutionContext, IActivityBlueprint activity, CancellationToken cancellationToken)
        {
            try
            {
                if (!await CanExecuteAsync(workflowExecutionContext, activity, true, cancellationToken))
                {
                    return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity.Id, null, false));
                }

                var blockingActivities = workflowExecutionContext.WorkflowInstance.BlockingActivities.Where(x => x.ActivityId == activity.Id).ToList();

                foreach (var blockingActivity in blockingActivities)
                {
                    await workflowExecutionContext.RemoveBlockingActivityAsync(blockingActivity);
                }

                var currentStatus = workflowExecutionContext.WorkflowInstance.WorkflowStatus;
                workflowExecutionContext.Resume();
                workflowExecutionContext.ScheduleActivity(activity.Id);
                await _mediator.Publish(new WorkflowStatusChanged(workflowExecutionContext.WorkflowInstance, workflowExecutionContext.WorkflowInstance.WorkflowStatus, currentStatus), cancellationToken);
                await RunCoreAsync(workflowExecutionContext, Resume, cancellationToken);

                return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity.Id, null, true));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Failed to run workflow {WorkflowInstanceId}", workflowExecutionContext.WorkflowInstance.Id);
                workflowExecutionContext.Fault(e, activity.Id, null, false);
                workflowExecutionContext.AddEntry(activity, "Faulted", null, SimpleException.FromException(e));
                return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity.Id, e, false));
            }
        }
Example #2
0
        private async Task <RunWorkflowResult> BeginWorkflow(WorkflowExecutionContext workflowExecutionContext, IActivityBlueprint?activity, CancellationToken cancellationToken)
        {
            if (activity == null)
            {
                activity = _startingActivitiesProvider.GetStartActivities(workflowExecutionContext.WorkflowBlueprint).FirstOrDefault() ?? workflowExecutionContext.WorkflowBlueprint.Activities.First();
            }

            try
            {
                if (!await CanExecuteAsync(workflowExecutionContext, activity, false, cancellationToken))
                {
                    return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity.Id, null, false));
                }

                var currentStatus = workflowExecutionContext.WorkflowInstance.WorkflowStatus;
                workflowExecutionContext.Begin();
                workflowExecutionContext.ScheduleActivity(activity.Id);
                await _mediator.Publish(new WorkflowStatusChanged(workflowExecutionContext.WorkflowInstance, workflowExecutionContext.WorkflowInstance.WorkflowStatus, currentStatus), cancellationToken);
                await RunCoreAsync(workflowExecutionContext, Execute, cancellationToken);

                return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity?.Id, null, true));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Failed to run workflow {WorkflowInstanceId}", workflowExecutionContext.WorkflowInstance.Id);
                workflowExecutionContext.Fault(e, activity?.Id, null, false);

                if (activity != null)
                {
                    workflowExecutionContext.AddEntry(activity, "Faulted", null, SimpleException.FromException(e));
                }

                return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity?.Id, e, false));
            }
        }
Example #3
0
        private async Task <RunWorkflowResult> RunWorkflowAsync(WorkflowExecutionContext workflowExecutionContext, IActivityBlueprint?activity, CancellationToken cancellationToken)
        {
            try
            {
                await RunCoreAsync(workflowExecutionContext, Execute, cancellationToken);

                return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity?.Id, null, true));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Failed to run workflow {WorkflowInstanceId}", workflowExecutionContext.WorkflowInstance.Id);
                workflowExecutionContext.Fault(e, null, null, false);

                if (activity != null)
                {
                    workflowExecutionContext.AddEntry(activity, "Faulted", null, SimpleException.FromException(e));
                }

                return(new RunWorkflowResult(workflowExecutionContext.WorkflowInstance, activity?.Id, e, false));
            }
        }