public async Task ThenThereShouldBeANewWorkflowInstanceInTheWorkflowInstanceStore(int expected) { ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>(); IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false); IEnumerable <string> instances = await store.GetMatchingWorkflowInstanceIdsForSubjectsAsync(Array.Empty <string>(), int.MaxValue, 0).ConfigureAwait(false); Assert.AreEqual(expected, instances.Count()); }
public async Task TheWorkflowInstanceStoreIsEmpty() { ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>(); IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false); IEnumerable <string> instanceIds = await store.GetMatchingWorkflowInstanceIdsForSubjectsAsync(Array.Empty <string>(), int.MaxValue, 0).ConfigureAwait(false); foreach (string current in instanceIds) { await store.DeleteWorkflowInstanceAsync(current).ConfigureAwait(false); } }
/// <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 _); } }
public async Task <string[]> RunAction( [ActivityTrigger] IDurableActivityContext context) { WorkflowMessageEnvelope envelope = context.GetInputWithCustomSerializationSettings <WorkflowMessageEnvelope>(this.serializerSettingsProvider.Instance); ITenant tenant = await this.tenantProvider.GetTenantAsync(envelope.TenantId); IWorkflowInstanceStore instanceStore = await this.workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenant); IEnumerable <string> instanceIds = await instanceStore.GetMatchingWorkflowInstanceIdsForSubjectsAsync( envelope.Trigger.GetSubjects(), 500, envelope.GetWorkflowInstancesPageNumber()); return(instanceIds.ToArray()); }