Skip to content

Commit 41b85c3

Browse files
authored
Merge pull request #1123 from glucaci/fixMongoPersistWorkflow
[Bug] Fix MongoDB persist workflow when no subscription
2 parents 30781e3 + 86ed4fa commit 41b85c3

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<PackageLicenseUrl>https://github.com/danielgerlag/workflow-core/blob/master/LICENSE.md</PackageLicenseUrl>
55
<RepositoryType>git</RepositoryType>
66
<RepositoryUrl>https://github.com/danielgerlag/workflow-core.git</RepositoryUrl>
7-
<Version>3.8.0</Version>
8-
<AssemblyVersion>3.8.0.0</AssemblyVersion>
9-
<FileVersion>3.8.0.0</FileVersion>
7+
<Version>3.8.1</Version>
8+
<AssemblyVersion>3.8.1.0</AssemblyVersion>
9+
<FileVersion>3.8.1.0</FileVersion>
1010
<PackageIconUrl>https://github.com/danielgerlag/workflow-core/raw/master/src/logo.png</PackageIconUrl>
11-
<PackageVersion>3.8.0</PackageVersion>
11+
<PackageVersion>3.8.1</PackageVersion>
1212
</PropertyGroup>
1313
</Project>

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)