-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add workflow client updater for updating workflow client (#258)
- Loading branch information
Showing
8 changed files
with
287 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Temporalio.Extensions.Hosting/TemporalWorkerClientUpdater.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using Temporalio.Worker; | ||
|
||
namespace Temporalio.Extensions.Hosting | ||
{ | ||
/// <summary> | ||
/// Notification hub that can be used to push Temporal worker client updates to subscribing Temporal workers. | ||
/// </summary> | ||
public class TemporalWorkerClientUpdater | ||
{ | ||
private readonly object clientLock = new(); | ||
|
||
private event EventHandler<IWorkerClient>? OnClientUpdatedEvent; | ||
|
||
/// <summary> | ||
/// Dispatches a notification to all subscribers that a new worker client should be used. | ||
/// </summary> | ||
/// <param name="client">The new <see cref="IWorkerClient"/> that should be pushed out to all subscribing workers.</param> | ||
public void UpdateClient(IWorkerClient client) | ||
{ | ||
OnClientUpdatedEvent?.Invoke(this, client); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a new subscriber that will be notified when a new worker client should be used. | ||
/// </summary> | ||
/// <param name="eventHandler">The event handler to add to the event listeners.</param> | ||
internal void Subscribe(EventHandler<IWorkerClient> eventHandler) | ||
{ | ||
lock (clientLock) | ||
{ | ||
OnClientUpdatedEvent += eventHandler; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Removes an existing subscriber from receiving notifications when a new worker client should be used. | ||
/// </summary> | ||
/// <param name="eventHandler">The event handler to remove from the event listeners.</param> | ||
internal void Unsubscribe(EventHandler<IWorkerClient> eventHandler) | ||
{ | ||
lock (clientLock) | ||
{ | ||
OnClientUpdatedEvent -= eventHandler; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.