Ejemplo n.º 1
0
        public async Task <IActionResult> Handle(string id, CancellationToken cancellationToken = default)
        {
            var result = await _canceller.CancelAsync(id, cancellationToken);

            return(result.Status switch
            {
                CancelWorkflowInstanceResultStatus.NotFound => NotFound(),
                CancelWorkflowInstanceResultStatus.InvalidStatus => BadRequest($"Cannot cancel a workflow instance with status {result.WorkflowInstance!.WorkflowStatus}"),
                _ => Ok()
            });
Ejemplo n.º 2
0
        public async Task <IActionResult> Handle(BulkCancelWorkflowsRequest request, CancellationToken cancellationToken = default)
        {
            var tasks   = request.WorkflowInstanceIds.Select(x => _workflowInstanceCanceller.CancelAsync(x, cancellationToken));
            var results = await Task.WhenAll(tasks);

            var count = results.Where(x => x.Status == CancelWorkflowInstanceResultStatus.Ok);

            return(Json(new
            {
                CancelledWorkflowCount = count
            }, _serializerSettingsProvider.GetSettings()));
        }
        public async Task <CancelWorkflowInstanceResult> CancelAsync(string workflowInstanceId, CancellationToken cancellationToken = default)
        {
            var workflowInstanceLockKey = $"workflow-instance:{workflowInstanceId}";

            await using var workflowInstanceLockHandle = await _distributedLockProvider.AcquireLockAsync(workflowInstanceLockKey, _elsaOptions.DistributedLockTimeout, cancellationToken);

            if (workflowInstanceLockHandle == null)
            {
                throw new LockAcquisitionException("Could not acquire a lock within the configured amount of time");
            }

            return(await _workflowInstanceCanceller.CancelAsync(workflowInstanceId, cancellationToken));
        }