Exemplo n.º 1
0
        protected override async ValueTask <IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
        {
            // Persist the workflow before sending the signal. This fixes a use case where a responding workflow sends a response signal handled by this workflow in a separate branch for example.
            await _workflowInstanceStore.SaveAsync(context.WorkflowInstance, context.CancellationToken);

            // Trigger the signal synchronously. If we dispatched the signal instead, we don;t have to explicitly save the workflow instance. For future reconsideration.
            await _signaler.DispatchSignalAsync(Signal, Input, correlationId : CorrelationId, cancellationToken : context.CancellationToken);

            return(Done());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Handle(string signalName, DispatchSignalRequest request, CancellationToken cancellationToken = default)
        {
            var result = await _signaler.DispatchSignalAsync(signalName, request.Input, request.WorkflowInstanceId, request.CorrelationId, cancellationToken).ToList();

            if (Response.HasStarted)
            {
                return(new EmptyResult());
            }

            return(Json(new DispatchSignalResponse(result), _serializerSettingsProvider.GetSettings()));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Handle(string token, CancellationToken cancellationToken)
        {
            if (!_tokenService.TryDecryptToken(token, out Signal signal))
            {
                return(NotFound());
            }

            await _signaler.DispatchSignalAsync(signal.Name, null, signal.WorkflowInstanceId, cancellationToken);

            return(Accepted());
        }
Exemplo n.º 4
0
        protected override async ValueTask <IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
        {
            // Persist the workflow before sending the signal. This fixes a use case where a responding workflow sends a response signal handled by this workflow in a separate branch for example.
            await _workflowInstanceStore.SaveAsync(context.WorkflowInstance, context.CancellationToken);

            // Trigger the signal synchronously. If we dispatched the signal instead, we don't have to explicitly save the workflow instance. For future reconsideration.
            // Warning: Sending a signal directly instead of dispatching it can potentially cause a deadlock if another workflow sends a signal back to this workflow immediately.

            switch (SendMode)
            {
            case SendSignalMode.Synchronously:
                await _signaler.TriggerSignalAsync(Signal, Input, correlationId : CorrelationId, cancellationToken : context.CancellationToken);

                break;

            case SendSignalMode.Asynchronously:
            default:
                await _signaler.DispatchSignalAsync(Signal, Input, correlationId : CorrelationId, cancellationToken : context.CancellationToken);

                break;
            }

            return(Done());
        }