-
Notifications
You must be signed in to change notification settings - Fork 44
feat: add workflow client updater for updating workflow client #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,21 @@ | ||
| using System; | ||
|
|
||
| namespace Temporalio.Worker | ||
| { | ||
| /// <summary> | ||
| /// Represents a notification hub that can be used to push worker client updates to subscribing workers. | ||
| /// </summary> | ||
| public interface IWorkerClientUpdater | ||
| { | ||
| /// <summary> | ||
| /// The event for when a worker client update is broadcast. | ||
| /// </summary> | ||
| event EventHandler<WorkerClientUpdatedEventArgs> OnWorkerClientUpdated; | ||
|
|
||
| /// <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> | ||
| void UpdateWorkerClient(IWorkerClient client); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
| using System; | ||
| using Temporalio.Client; | ||
|
|
||
| namespace Temporalio.Worker | ||
| { | ||
| /// <summary> | ||
| /// Event raised when a worker client is updated. | ||
| /// </summary> | ||
| public class WorkerClientUpdatedEventArgs : EventArgs | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="WorkerClientUpdatedEventArgs"/> class. | ||
| /// </summary> | ||
| /// <param name="workerClient">The client to update workers with.</param> | ||
| public WorkerClientUpdatedEventArgs(IWorkerClient workerClient) => WorkerClient = workerClient; | ||
|
|
||
| /// <summary> | ||
| /// Gets the <see cref="ITemporalClient"/> that will be propagated to all event listeners. | ||
| /// </summary> | ||
| public IWorkerClient WorkerClient { get; } | ||
| } | ||
| } |
This file contains hidden or 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,44 @@ | ||
| using System; | ||
|
|
||
| namespace Temporalio.Worker | ||
| { | ||
| /// <summary> | ||
| /// Implementation of the <see cref="IWorkerClientUpdater"/>. | ||
| /// </summary> | ||
| public class WorkerClientUpdater : IWorkerClientUpdater | ||
| { | ||
| private readonly object clientLock = new(); | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="EventHandler"/> used to dispatch notifications to subscribers that the client was updated. | ||
| /// </summary> | ||
| public event EventHandler<WorkerClientUpdatedEventArgs> OnWorkerClientUpdated | ||
| { | ||
| add | ||
| { | ||
| lock (clientLock) | ||
| { | ||
| WorkerClientUpdatedEvent += value; | ||
| } | ||
| } | ||
|
|
||
| remove | ||
| { | ||
| lock (clientLock) | ||
| { | ||
| WorkerClientUpdatedEvent -= value; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private event EventHandler<WorkerClientUpdatedEventArgs>? WorkerClientUpdatedEvent; | ||
|
|
||
| /// <inheritdoc /> | ||
| public void UpdateWorkerClient(IWorkerClient client) | ||
| { | ||
| WorkerClientUpdatedEventArgs eventArgs = new WorkerClientUpdatedEventArgs(client); | ||
|
|
||
| WorkerClientUpdatedEvent?.Invoke(this, eventArgs); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think any of this is needed in the
Temporalioproject. This is a generic host problem only. Those making workers directly can just use theClientsetter. I also don't think an interface is needed unless you really think it's important for testing (even then not sure the event handler needs to be part of the interface). Also, even though it's a mouthful, I'd call thisTemporalWorkerClientUpdaterw/ theTemporalprefix to match the worker class name for discoverability.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, done.
I don't think a lack of an interface hampers testing, since the implementation has no dependencies