public async Task <OpenApiResult> HandleTrigger(string tenantId, string workflowInstanceId, IWorkflowTrigger body) { ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(tenantId).ConfigureAwait(false); IWorkflowEngine workflowEngine = await this.workflowEngineFactory.GetWorkflowEngineAsync(tenant).ConfigureAwait(false); await workflowEngine.ProcessTriggerAsync(body, workflowInstanceId).ConfigureAwait(false); return(this.OkResult()); }
/// <summary> /// The Process method is invoked asynchronously when <see cref="StartProcessing" /> is /// called. It will run on a background thread until <see cref="FinishProcessing" /> /// is called. /// </summary> /// <returns> /// A <see cref="Task" /> that will complete after <see cref="FinishProcessing" /> is called. /// </returns> private async Task Process() { while (true) { if (this.queue.IsEmpty) { if (this.shouldComplete) { break; } await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); continue; } this.queue.TryPeek(out WorkflowMessageEnvelope item); IWorkflowInstanceStore instanceStore = await this.workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(this.tenantProvider.Root).ConfigureAwait(false); IWorkflowEngine engine = await this.workflowEngineFactory.GetWorkflowEngineAsync(this.tenantProvider.Root).ConfigureAwait(false); if (item.IsTrigger) { this.logger.LogInformation("Processing trigger with content type {ContentType}", item.ContentType); IWorkflowTrigger trigger = item.Trigger; IEnumerable <string> instanceIds = await instanceStore.GetMatchingWorkflowInstanceIdsForSubjectsAsync( item.Trigger.GetSubjects(), int.MaxValue, 0).ConfigureAwait(false); foreach (string current in instanceIds) { await engine.ProcessTriggerAsync(trigger, current).ConfigureAwait(false); } } else { this.logger.LogInformation("Processing start workflow instance request"); await engine.StartWorkflowInstanceAsync(item.StartWorkflowInstanceRequest) .ConfigureAwait(false); } this.queue.TryDequeue(out _); } }