Skip to content

Commit 1ff237f

Browse files
authored
Merge pull request danielgerlag#387 from AMalininHere/hosted-service-support
Compatibility with IHostedService
2 parents 56fb846 + caeaa4d commit 1ff237f

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/WorkflowCore/Interface/IWorkflowHost.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using Microsoft.Extensions.Logging;
22
using System;
3-
using System.Threading.Tasks;
3+
using Microsoft.Extensions.Hosting;
44
using WorkflowCore.Models;
55
using WorkflowCore.Models.LifeCycleEvents;
66

77
namespace WorkflowCore.Interface
88
{
9-
public interface IWorkflowHost : IWorkflowController
9+
public interface IWorkflowHost : IWorkflowController, IHostedService
1010
{
1111
/// <summary>
1212
/// Start the workflow host, this enable execution of workflows

src/WorkflowCore/Services/WorkflowHost.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,18 @@ public Task PublishEvent(string eventName, string eventKey, object eventData, Da
7878
}
7979

8080
public void Start()
81+
{
82+
StartAsync(CancellationToken.None).Wait();
83+
}
84+
85+
public async Task StartAsync(CancellationToken cancellationToken)
8186
{
8287
_shutdown = false;
8388
PersistenceStore.EnsureStoreExists();
84-
QueueProvider.Start().Wait();
85-
LockProvider.Start().Wait();
86-
_lifeCycleEventHub.Start().Wait();
87-
_searchIndex.Start().Wait();
89+
await QueueProvider.Start();
90+
await LockProvider.Start();
91+
await _lifeCycleEventHub.Start();
92+
await _searchIndex.Start();
8893

8994
Logger.LogInformation("Starting background tasks");
9095

@@ -93,6 +98,11 @@ public void Start()
9398
}
9499

95100
public void Stop()
101+
{
102+
StopAsync(CancellationToken.None).Wait();
103+
}
104+
105+
public async Task StopAsync(CancellationToken cancellationToken)
96106
{
97107
_shutdown = true;
98108

@@ -102,10 +112,10 @@ public void Stop()
102112

103113
Logger.LogInformation("Worker tasks stopped");
104114

105-
QueueProvider.Stop().Wait();
106-
LockProvider.Stop().Wait();
107-
_searchIndex.Stop().Wait();
108-
_lifeCycleEventHub.Stop().Wait();
115+
await QueueProvider.Stop();
116+
await LockProvider.Stop();
117+
await _searchIndex.Stop();
118+
await _lifeCycleEventHub.Stop();
109119
}
110120

111121
public void RegisterWorkflow<TWorkflow>()

src/WorkflowCore/WorkflowCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<ItemGroup>
2626
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.0" />
27+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.0" />
2728
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
2829
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="2.2.0" />
2930
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />

0 commit comments

Comments
 (0)