Skip to content

Commit 6a7ae38

Browse files
committed
Fix persist workflow when has no subscription
1 parent e00d53b commit 6a7ae38

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/WorkflowCore/Services/BackgroundTasks/WorkflowConsumer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected override async Task ProcessItem(string itemId, CancellationToken cance
5555
finally
5656
{
5757
WorkflowActivity.Enrich(result);
58-
await _persistenceStore.PersistWorkflow(workflow, result.Subscriptions, cancellationToken);
58+
await _persistenceStore.PersistWorkflow(workflow, result?.Subscriptions, cancellationToken);
5959
await QueueProvider.QueueWork(itemId, QueueType.Index);
6060
_greylist.Remove($"wf:{itemId}");
6161
}

src/providers/WorkflowCore.Persistence.MongoDB/Services/MongoPersistenceProvider.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,18 @@ public async Task PersistWorkflow(WorkflowInstance workflow, CancellationToken c
154154

155155
public async Task PersistWorkflow(WorkflowInstance workflow, List<EventSubscription> subscriptions, CancellationToken cancellationToken = default)
156156
{
157-
using (var session = await _database.Client.StartSessionAsync())
157+
if (subscriptions == null || subscriptions.Count < 1)
158+
{
159+
await PersistWorkflow(workflow, cancellationToken);
160+
return;
161+
}
162+
163+
using (var session = await _database.Client.StartSessionAsync(cancellationToken: cancellationToken))
158164
{
159165
session.StartTransaction();
160166
await PersistWorkflow(workflow, cancellationToken);
161167
await EventSubscriptions.InsertManyAsync(subscriptions, cancellationToken: cancellationToken);
162-
await session.CommitTransactionAsync();
168+
await session.CommitTransactionAsync(cancellationToken);
163169
}
164170
}
165171

0 commit comments

Comments
 (0)