diff --git a/src/Temporalio/Worker/TemporalWorker.cs b/src/Temporalio/Worker/TemporalWorker.cs index 9505b6e7..715a1de4 100644 --- a/src/Temporalio/Worker/TemporalWorker.cs +++ b/src/Temporalio/Worker/TemporalWorker.cs @@ -89,7 +89,8 @@ public TemporalWorker(IWorkerClient client, TemporalWorkerOptions options) OnTaskStarting: options.OnTaskStarting, OnTaskCompleted: options.OnTaskCompleted, RuntimeMetricMeter: MetricMeter, - WorkerLevelFailureExceptionTypes: options.WorkflowFailureExceptionTypes)); + WorkerLevelFailureExceptionTypes: options.WorkflowFailureExceptionTypes, + DisableEagerActivityExecution: options.DisableEagerActivityExecution)); } } diff --git a/src/Temporalio/Worker/TemporalWorkerOptions.cs b/src/Temporalio/Worker/TemporalWorkerOptions.cs index 24f9a051..5b1c92e9 100644 --- a/src/Temporalio/Worker/TemporalWorkerOptions.cs +++ b/src/Temporalio/Worker/TemporalWorkerOptions.cs @@ -283,6 +283,21 @@ public TemporalWorkerOptions() /// public WorkerTuner? Tuner { get; set; } + /// + /// Gets or sets a value indicating whether eager activity executions will be disabled from + /// a workflow. + /// + /// + /// Eager activity execution is an optimization on some servers that sends activities back + /// to the same worker as the calling workflow if they can run there. + /// + /// + /// This should be set to true for to + /// work and in a future version of this API may be implied as such (i.e. this setting will + /// be ignored if that setting is set). + /// + public bool DisableEagerActivityExecution { get; set; } + /// /// Gets the TEMPORAL_DEBUG environment variable. /// diff --git a/src/Temporalio/Worker/WorkflowInstance.cs b/src/Temporalio/Worker/WorkflowInstance.cs index dfafc16d..fdc3e4b7 100644 --- a/src/Temporalio/Worker/WorkflowInstance.cs +++ b/src/Temporalio/Worker/WorkflowInstance.cs @@ -69,6 +69,7 @@ internal class WorkflowInstance : TaskScheduler, IWorkflowInstance, IWorkflowCon private readonly Action onTaskStarting; private readonly Action onTaskCompleted; private readonly IReadOnlyCollection? workerLevelFailureExceptionTypes; + private readonly bool disableEagerActivityExecution; private readonly Handlers inProgressHandlers = new(); private WorkflowActivationCompletion? completion; // Will be set to null after last use (i.e. when workflow actually started) @@ -190,6 +191,7 @@ public WorkflowInstance(WorkflowInstanceDetails details) Random = new(details.Start.RandomnessSeed); TracingEventsEnabled = !details.DisableTracingEvents; workerLevelFailureExceptionTypes = details.WorkerLevelFailureExceptionTypes; + disableEagerActivityExecution = details.DisableEagerActivityExecution; } /// @@ -1756,6 +1758,7 @@ public override Task ScheduleActivityAsync( Arguments = { instance.PayloadConverter.ToPayloads(input.Args) }, RetryPolicy = input.Options.RetryPolicy?.ToProto(), CancellationType = (Bridge.Api.WorkflowCommands.ActivityCancellationType)input.Options.CancellationType, + DoNotEagerlyExecute = instance.disableEagerActivityExecution || input.Options.DisableEagerActivityExecution, }; if (input.Headers is IDictionary headers) { diff --git a/src/Temporalio/Worker/WorkflowInstanceDetails.cs b/src/Temporalio/Worker/WorkflowInstanceDetails.cs index d2c569a8..f2607593 100644 --- a/src/Temporalio/Worker/WorkflowInstanceDetails.cs +++ b/src/Temporalio/Worker/WorkflowInstanceDetails.cs @@ -26,6 +26,7 @@ namespace Temporalio.Worker /// Callback for every instance task complete. /// Lazy runtime-level metric meter. /// Failure exception types at worker level. + /// Whether to disable eager at the worker level. internal record WorkflowInstanceDetails( string Namespace, string TaskQueue, @@ -41,5 +42,6 @@ internal record WorkflowInstanceDetails( Action OnTaskStarting, Action OnTaskCompleted, Lazy RuntimeMetricMeter, - IReadOnlyCollection? WorkerLevelFailureExceptionTypes); + IReadOnlyCollection? WorkerLevelFailureExceptionTypes, + bool DisableEagerActivityExecution); } \ No newline at end of file diff --git a/src/Temporalio/Worker/WorkflowReplayer.cs b/src/Temporalio/Worker/WorkflowReplayer.cs index 3e7dafa9..2124fc03 100644 --- a/src/Temporalio/Worker/WorkflowReplayer.cs +++ b/src/Temporalio/Worker/WorkflowReplayer.cs @@ -173,7 +173,8 @@ public WorkflowHistoryRunner(WorkflowReplayerOptions options, bool throwOnReplay OnTaskStarting: options.OnTaskStarting, OnTaskCompleted: options.OnTaskCompleted, RuntimeMetricMeter: new(() => runtime.MetricMeter), - WorkerLevelFailureExceptionTypes: options.WorkflowFailureExceptionTypes), + WorkerLevelFailureExceptionTypes: options.WorkflowFailureExceptionTypes, + DisableEagerActivityExecution: false), (runId, removeFromCache) => SetResult(removeFromCache)); } catch diff --git a/src/Temporalio/Worker/WorkflowWorker.cs b/src/Temporalio/Worker/WorkflowWorker.cs index 3d37dd9a..7ac0c6d5 100644 --- a/src/Temporalio/Worker/WorkflowWorker.cs +++ b/src/Temporalio/Worker/WorkflowWorker.cs @@ -283,7 +283,8 @@ private IWorkflowInstance CreateInstance(WorkflowActivation act) OnTaskStarting: options.OnTaskStarting, OnTaskCompleted: options.OnTaskCompleted, RuntimeMetricMeter: options.RuntimeMetricMeter, - WorkerLevelFailureExceptionTypes: options.WorkerLevelFailureExceptionTypes)); + WorkerLevelFailureExceptionTypes: options.WorkerLevelFailureExceptionTypes, + DisableEagerActivityExecution: options.DisableEagerActivityExecution)); } } } \ No newline at end of file diff --git a/src/Temporalio/Worker/WorkflowWorkerOptions.cs b/src/Temporalio/Worker/WorkflowWorkerOptions.cs index a56865b7..bf2f3e5e 100644 --- a/src/Temporalio/Worker/WorkflowWorkerOptions.cs +++ b/src/Temporalio/Worker/WorkflowWorkerOptions.cs @@ -21,5 +21,6 @@ internal record WorkflowWorkerOptions( Action OnTaskStarting, Action OnTaskCompleted, Lazy RuntimeMetricMeter, - IReadOnlyCollection? WorkerLevelFailureExceptionTypes); + IReadOnlyCollection? WorkerLevelFailureExceptionTypes, + bool DisableEagerActivityExecution); } \ No newline at end of file diff --git a/src/Temporalio/Workflows/ActivityOptions.cs b/src/Temporalio/Workflows/ActivityOptions.cs index b045f34f..2cb4de01 100644 --- a/src/Temporalio/Workflows/ActivityOptions.cs +++ b/src/Temporalio/Workflows/ActivityOptions.cs @@ -85,6 +85,20 @@ public class ActivityOptions : ICloneable /// public VersioningIntent VersioningIntent { get; set; } = VersioningIntent.Unspecified; + /// + /// Gets or sets a value indicating whether eager activity execution will be disabled for + /// this activity. + /// + /// + /// Eager activity execution is an optimization on some servers that sends activities back + /// to the same worker as the calling workflow if they can run there. + /// + /// + /// If false (the default), eager execution may still be disabled at the worker level + /// or may not be requested due to lack of available slots. + /// + public bool DisableEagerActivityExecution { get; set; } + /// /// Create a shallow copy of these options. ///