-
Notifications
You must be signed in to change notification settings - Fork 216
Let activities heartbeat during worker shutdown #2903
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -358,7 +358,9 @@ public WorkflowClient getWorkflowClient() { | |||||||||
| * activity tasks are executed. <br> | ||||||||||
| * After the shutdown, calls to {@link | ||||||||||
| * io.temporal.activity.ActivityExecutionContext#heartbeat(Object)} start throwing {@link | ||||||||||
| * io.temporal.client.ActivityWorkerShutdownException}.<br> | ||||||||||
| * io.temporal.client.ActivityWorkerShutdownException}, unless {@link | ||||||||||
| * WorkerOptions.Builder#setActivityHeartbeatDuringShutdown(boolean)} is enabled, in which case | ||||||||||
| * heartbeats keep working until the activity tasks finish executing.<br> | ||||||||||
| * This method does not wait for the shutdown to complete. Use {@link #awaitTermination(long, | ||||||||||
| * TimeUnit)} to do that.<br> | ||||||||||
| * Invocation has no additional effect if already shut down. | ||||||||||
|
|
@@ -375,7 +377,9 @@ public synchronized void shutdown() { | |||||||||
| * interrupts may never terminate.<br> | ||||||||||
| * After the shutdownNow calls to {@link | ||||||||||
| * io.temporal.activity.ActivityExecutionContext#heartbeat(Object)} start throwing {@link | ||||||||||
| * io.temporal.client.ActivityWorkerShutdownException}.<br> | ||||||||||
| * io.temporal.client.ActivityWorkerShutdownException}, unless {@link | ||||||||||
| * WorkerOptions.Builder#setActivityHeartbeatDuringShutdown(boolean)} is enabled, in which case | ||||||||||
| * heartbeats keep working until the activity tasks finish executing.<br> | ||||||||||
|
Comment on lines
+380
to
+382
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| * This method does not wait for the shutdown to complete. Use {@link #awaitTermination(long, | ||||||||||
| * TimeUnit)} to do that.<br> | ||||||||||
| * Invocation has no additional effect if already shut down. | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -77,6 +77,7 @@ public static final class Builder { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private PollerBehavior workflowTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private PollerBehavior activityTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private PollerBehavior nexusTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private boolean activityHeartbeatDuringShutdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field should be named |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private Builder() {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -112,6 +113,7 @@ private Builder(WorkerOptions o) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.workflowTaskPollersBehavior = o.workflowTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.activityTaskPollersBehavior = o.activityTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.nexusTaskPollersBehavior = o.nexusTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.activityHeartbeatDuringShutdown = o.activityHeartbeatDuringShutdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -524,6 +526,29 @@ public Builder setNexusTaskPollersBehavior(PollerBehavior pollerBehavior) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * If enabled, activities can keep heartbeating while the worker is shutting down. The activity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * heartbeat executor is closed only after all outstanding activity tasks have finished | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * executing, so {@link io.temporal.activity.ActivityExecutionContext#heartbeat(Object)} behaves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * exactly as it does while the worker is running: heartbeats are throttled and sent to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * server, which keeps the server from timing the activity out during the {@link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * WorkerFactory#awaitTermination(long, java.util.concurrent.TimeUnit)} grace period. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * <p>Note that with this option enabled activities are no longer notified of the worker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * shutdown by an {@link io.temporal.client.ActivityWorkerShutdownException} thrown from {@code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * heartbeat}, so they are expected to complete within the termination grace period on their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * <p>Defaults to false, meaning that after shutdown is requested, {@link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * io.temporal.activity.ActivityExecutionContext#heartbeat(Object)} stops sending heartbeats and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * throws {@link io.temporal.client.ActivityWorkerShutdownException}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Experimental | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public Builder setActivityHeartbeatDuringShutdown(boolean activityHeartbeatDuringShutdown) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+529
to
+547
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to document implementation details.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.activityHeartbeatDuringShutdown = activityHeartbeatDuringShutdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public WorkerOptions build() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new WorkerOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| maxWorkerActivitiesPerSecond, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -553,7 +578,8 @@ public WorkerOptions build() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deploymentOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workflowTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| activityTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nexusTaskPollersBehavior); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nexusTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| activityHeartbeatDuringShutdown); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public WorkerOptions validateAndBuildWithDefaults() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -685,7 +711,8 @@ public WorkerOptions validateAndBuildWithDefaults() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deploymentOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workflowTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| activityTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nexusTaskPollersBehavior); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nexusTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| activityHeartbeatDuringShutdown); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -717,6 +744,7 @@ public WorkerOptions validateAndBuildWithDefaults() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final PollerBehavior workflowTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final PollerBehavior activityTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final PollerBehavior nexusTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final boolean activityHeartbeatDuringShutdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private WorkerOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double maxWorkerActivitiesPerSecond, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -746,7 +774,8 @@ private WorkerOptions( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WorkerDeploymentOptions deploymentOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PollerBehavior workflowTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PollerBehavior activityTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PollerBehavior nexusTaskPollersBehavior) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PollerBehavior nexusTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean activityHeartbeatDuringShutdown) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.maxWorkerActivitiesPerSecond = maxWorkerActivitiesPerSecond; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.maxConcurrentActivityExecutionSize = maxConcurrentActivityExecutionSize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.maxConcurrentWorkflowTaskExecutionSize = maxConcurrentWorkflowTaskExecutionSize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -775,6 +804,7 @@ private WorkerOptions( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.workflowTaskPollersBehavior = workflowTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.activityTaskPollersBehavior = activityTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.nexusTaskPollersBehavior = nexusTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.activityHeartbeatDuringShutdown = activityHeartbeatDuringShutdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public double getMaxWorkerActivitiesPerSecond() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -912,6 +942,14 @@ public PollerBehavior getNexusTaskPollersBehavior() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nexusTaskPollersBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return true if activities keep heartbeating while the worker is shutting down | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Experimental | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean isActivityHeartbeatDuringShutdown() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return activityHeartbeatDuringShutdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean equals(Object o) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this == o) return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -944,7 +982,8 @@ && compare(maxTaskQueueActivitiesPerSecond, that.maxTaskQueueActivitiesPerSecond | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && Objects.equals(deploymentOptions, that.deploymentOptions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && Objects.equals(workflowTaskPollersBehavior, that.workflowTaskPollersBehavior) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && Objects.equals(activityTaskPollersBehavior, that.activityTaskPollersBehavior) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && Objects.equals(nexusTaskPollersBehavior, that.nexusTaskPollersBehavior); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && Objects.equals(nexusTaskPollersBehavior, that.nexusTaskPollersBehavior) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && activityHeartbeatDuringShutdown == that.activityHeartbeatDuringShutdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -977,7 +1016,8 @@ public int hashCode() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deploymentOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workflowTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| activityTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nexusTaskPollersBehavior); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nexusTaskPollersBehavior, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| activityHeartbeatDuringShutdown); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1040,6 +1080,8 @@ public String toString() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + activityTaskPollersBehavior | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + ", nexusTaskPollersBehavior=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + nexusTaskPollersBehavior | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + ", activityHeartbeatDuringShutdown=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + activityHeartbeatDuringShutdown | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
When
interruptTasksis true (shutdownNowwas called instead ofshutdown), it should behave as if heartbeat during shutdown was disabled.