Skip to content

Commit d283e05

Browse files
committed
Review comments
1 parent 3704e74 commit d283e05

File tree

10 files changed

+34
-41
lines changed

10 files changed

+34
-41
lines changed

temporalio/lib/temporalio/internal/worker/workflow_instance.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
require 'temporalio/retry_policy'
2525
require 'temporalio/scoped_logger'
2626
require 'temporalio/worker/interceptor'
27+
require 'temporalio/worker_deployment_version'
2728
require 'temporalio/workflow/info'
2829
require 'temporalio/workflow/update_info'
2930
require 'timeout'
@@ -90,7 +91,7 @@ def initialize(details)
9091
@current_history_length = 0
9192
@current_history_size = 0
9293
@replaying = false
93-
@failure_exception_types = details.workflow_failure_exception_types + @definition.failure_exception_types
94+
@workflow_failure_exception_types = details.workflow_failure_exception_types
9495
@signal_handlers = HandlerHash.new(
9596
details.definition.signals,
9697
Workflow::Definition::Signal
@@ -324,14 +325,12 @@ def create_instance
324325
end
325326

326327
# Run Dynamic config getter
327-
unless @definition.dynamic_options_method.nil?
328-
dynamic_options = instance.send @definition.dynamic_options_method
329-
end
330-
unless dynamic_options.nil?
331-
unless dynamic_options.versioning_behavior.nil?
328+
if @definition.dynamic_options_method
329+
dynamic_options = instance.send(@definition.dynamic_options_method)
330+
if dynamic_options&.versioning_behavior
332331
@definition_options.versioning_behavior = dynamic_options.versioning_behavior
333332
end
334-
unless dynamic_options.failure_exception_types.nil?
333+
if dynamic_options&.failure_exception_types
335334
@definition_options.failure_exception_types = dynamic_options.failure_exception_types
336335
end
337336
end
@@ -650,9 +649,11 @@ def on_top_level_exception(err)
650649
end
651650

652651
def failure_exception?(err)
653-
err.is_a?(Error::Failure) || err.is_a?(Timeout::Error) || @failure_exception_types.any? do |cls|
654-
err.is_a?(cls)
655-
end
652+
err.is_a?(Error::Failure) || err.is_a?(Timeout::Error) ||
653+
((@workflow_failure_exception_types || []) +
654+
(@definition_options.failure_exception_types || [])).any? do |cls|
655+
err.is_a?(cls)
656+
end
656657
end
657658

658659
def with_context_frozen(&)

temporalio/lib/temporalio/internal/worker/workflow_worker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Internal
1313
module Worker
1414
# Worker for handling workflow activations. Most activation work is delegated to the workflow executor.
1515
class WorkflowWorker
16-
def self.workflow_definitions(workflows, should_enforce_versioning_behavior: false)
16+
def self.workflow_definitions(workflows, should_enforce_versioning_behavior)
1717
workflows.each_with_object({}) do |workflow, hash|
1818
# Load definition
1919
defn = begin
@@ -31,7 +31,7 @@ def self.workflow_definitions(workflows, should_enforce_versioning_behavior: fal
3131

3232
# Enforce versioning behavior is set when versioning is on
3333
if should_enforce_versioning_behavior &&
34-
defn.versioning_behavior == VersioningBehavior::UNSPECIFIED && defn.dynamic_options_method.nil?
34+
defn.versioning_behavior == VersioningBehavior::UNSPECIFIED && !defn.dynamic_options_method
3535
raise ArgumentError, "Workflow #{defn.name} must specify a versioning behavior"
3636
end
3737

temporalio/lib/temporalio/worker.rb

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class Worker
3333
:activity_executors,
3434
:workflow_executor,
3535
:interceptors,
36-
:build_id,
3736
:identity,
3837
:logger,
3938
:max_cached_workflows,
@@ -47,7 +46,6 @@ class Worker
4746
:max_activities_per_second,
4847
:max_task_queue_activities_per_second,
4948
:graceful_shutdown_period,
50-
:use_worker_versioning,
5149
:disable_eager_activity_execution,
5250
:illegal_workflow_calls,
5351
:workflow_failure_exception_types,
@@ -297,10 +295,6 @@ def self.default_illegal_workflow_calls
297295
# @param interceptors [Array<Interceptor::Activity, Interceptor::Workflow>] Interceptors specific to this worker.
298296
# Note, interceptors set on the client that include the {Interceptor::Activity} or {Interceptor::Workflow} module
299297
# are automatically included here, so no need to specify them again.
300-
# @param build_id [String] Unique identifier for the current runtime. This is best set as a unique value
301-
# representing all code and should change only when code does. This can be something like a git commit hash. If
302-
# unset, default is hash of known Ruby code.
303-
# Exclusive with `deployment_options`.
304298
# @param identity [String, nil] Override the identity for this worker. If unset, client identity is used.
305299
# @param logger [Logger] Logger to override client logger with. Default is the client logger.
306300
# @param max_cached_workflows [Integer] Number of workflows held in cache for use by sticky task queue. If set to 0,
@@ -329,10 +323,6 @@ def self.default_illegal_workflow_calls
329323
# multiple workers on the same queue have different values set, they will thrash with the last poller winning.
330324
# @param graceful_shutdown_period [Float] Amount of time after shutdown is called that activities are given to
331325
# complete before their tasks are canceled.
332-
# @param use_worker_versioning [Boolean] If true, the `build_id` argument must be specified, and this worker opts
333-
# into the worker versioning feature. This ensures it only receives workflow tasks for workflows which it claims
334-
# to be compatible with. For more information, see https://docs.temporal.io/workers#worker-versioning.
335-
# Exclusive with `deployment_options`.
336326
# @param disable_eager_activity_execution [Boolean] If true, disables eager activity execution. Eager activity
337327
# execution is an optimization on some servers that sends activities back to the same worker as the calling
338328
# workflow if they can run there. This should be set to true for `max_task_queue_activities_per_second` to work
@@ -355,7 +345,6 @@ def self.default_illegal_workflow_calls
355345
# scheduler will fail. Instead of setting this to true, users are encouraged to use {Workflow::Unsafe.io_enabled}
356346
# with a block for narrower enabling of IO.
357347
# @param deployment_options [DeploymentOptions, nil] Deployment options for the worker.
358-
# Exclusive with `build_id` and `use_worker_versioning`.
359348
# WARNING: This is an experimental feature and may change in the future.
360349
# @param debug_mode [Boolean] If true, deadlock detection is disabled. Deadlock detection will fail workflow tasks
361350
# if they block the thread for too long. This defaults to true if the `TEMPORAL_DEBUG` environment variable is
@@ -369,7 +358,6 @@ def initialize(
369358
activity_executors: ActivityExecutor.defaults,
370359
workflow_executor: WorkflowExecutor::ThreadPool.default,
371360
interceptors: [],
372-
build_id: Worker.default_build_id,
373361
identity: nil,
374362
logger: client.options.logger,
375363
max_cached_workflows: 1000,
@@ -383,7 +371,6 @@ def initialize(
383371
max_activities_per_second: nil,
384372
max_task_queue_activities_per_second: nil,
385373
graceful_shutdown_period: 0,
386-
use_worker_versioning: false,
387374
disable_eager_activity_execution: false,
388375
illegal_workflow_calls: Worker.default_illegal_workflow_calls,
389376
workflow_failure_exception_types: [],
@@ -405,7 +392,6 @@ def initialize(
405392
activity_executors:,
406393
workflow_executor:,
407394
interceptors:,
408-
build_id:,
409395
identity:,
410396
logger:,
411397
max_cached_workflows:,
@@ -419,7 +405,6 @@ def initialize(
419405
max_activities_per_second:,
420406
max_task_queue_activities_per_second:,
421407
graceful_shutdown_period:,
422-
use_worker_versioning:,
423408
disable_eager_activity_execution:,
424409
illegal_workflow_calls:,
425410
workflow_failure_exception_types:,
@@ -436,7 +421,7 @@ def initialize(
436421
# Preload workflow definitions and some workflow settings for the bridge
437422
workflow_definitions = Internal::Worker::WorkflowWorker.workflow_definitions(
438423
workflows,
439-
should_enforce_versioning_behavior:
424+
should_enforce_versioning_behavior
440425
)
441426
nondeterminism_as_workflow_fail, nondeterminism_as_workflow_fail_for_types =
442427
Internal::Worker::WorkflowWorker.bridge_workflow_failure_exception_type_options(
@@ -452,7 +437,7 @@ def initialize(
452437
namespace: client.namespace,
453438
task_queue:,
454439
tuner: tuner._to_bridge_options,
455-
build_id:,
440+
build_id: '',
456441
identity_override: identity,
457442
max_cached_workflows:,
458443
max_concurrent_workflow_task_polls:,
@@ -467,7 +452,7 @@ def initialize(
467452
max_worker_activities_per_second: max_activities_per_second,
468453
max_task_queue_activities_per_second:,
469454
graceful_shutdown_period:,
470-
use_worker_versioning:,
455+
use_worker_versioning: false,
471456
nondeterminism_as_workflow_fail:,
472457
nondeterminism_as_workflow_fail_for_types:,
473458
deployment_options: if deployment_options.nil?

temporalio/lib/temporalio/worker/deployment_options.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# frozen_string_literal: true
22

3+
require 'temporalio/common_enums'
4+
require 'temporalio/worker_deployment_version'
5+
36
module Temporalio
47
class Worker
58
DeploymentOptions = Data.define(

temporalio/lib/temporalio/worker/workflow_replayer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def initialize(
116116
runtime:
117117
).freeze
118118
# Preload definitions and other settings
119-
@workflow_definitions = Internal::Worker::WorkflowWorker.workflow_definitions(workflows)
119+
@workflow_definitions = Internal::Worker::WorkflowWorker.workflow_definitions(workflows, false)
120120
@nondeterminism_as_workflow_fail, @nondeterminism_as_workflow_fail_for_types =
121121
Internal::Worker::WorkflowWorker.bridge_workflow_failure_exception_type_options(
122122
workflow_failure_exception_types:, workflow_definitions: @workflow_definitions

temporalio/lib/temporalio/worker_versioning.rb renamed to temporalio/lib/temporalio/worker_deployment_version.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require 'temporalio/internal/bridge/worker'
4+
35
module Temporalio
46
WorkerDeploymentVersion = Data.define(
57
:deployment_name,
@@ -12,6 +14,9 @@ module Temporalio
1214
class WorkerDeploymentVersion
1315
# Parse a version from a canonical string, which must be in the format
1416
# `<deployment_name>.<build_id>`. Deployment name must not have a `.` in it.
17+
#
18+
# @param canonical [String] The canonical string representation of the version.
19+
# @return [WorkerDeploymentVersion] The parsed version.
1520
def self.from_canonical_string(canonical)
1621
parts = canonical.split('.', 2)
1722
if parts.length != 2
@@ -23,6 +28,8 @@ def self.from_canonical_string(canonical)
2328

2429
# @!visibility private
2530
def self._from_bridge(bridge)
31+
return nil if bridge.nil?
32+
2633
new(deployment_name: bridge.deployment_name, build_id: bridge.build_id)
2734
end
2835

temporalio/lib/temporalio/workflow/definition.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ def workflow_update_validator(update_method)
202202
# will override those provided to other `workflow_xxx` setters.
203203
#
204204
# Cannot be specified on non-dynamic workflows.
205-
#
206-
# @param update_method [Symbol] Name of the dynamic options method.
207205
def workflow_dynamic_options
208206
raise 'Dynamic options method can only be set on workflows using `workflow_dynamic`' unless @workflow_dynamic
209207

@@ -421,6 +419,10 @@ def self._build_workflow_definition
421419

422420
raise 'Workflow cannot be given a name and be dynamic' if dynamic && override_name
423421

422+
if !dynamic && !@dynamic_options_method.nil?
423+
raise 'Workflow cannot have a dynamic_options_method unless it is dynamic'
424+
end
425+
424426
Info.new(
425427
workflow_class: self,
426428
override_name:,

temporalio/test/test.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ def initialize
147147
client = Temporalio::Client.connect(
148148
ENV['TEMPORAL_TEST_CLIENT_TARGET_HOST'],
149149
ENV['TEMPORAL_TEST_CLIENT_TARGET_NAMESPACE'] || 'default',
150-
data_converter: Temporalio::Converters::DataConverter.default,
151-
interceptors: [],
152-
logger: Logger.new($stdout, level: Logger::WARN),
153-
default_workflow_query_reject_condition: nil,
154-
runtime: Temporalio::Runtime.default
150+
logger: Logger.new($stdout)
155151
)
156152
@server = Temporalio::Testing::WorkflowEnvironment.new(client)
157153
else

temporalio/test/worker_activity_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ def assert_multi_worker_activities(activities)
660660
client: env.client,
661661
task_queue: "tq-#{index}-#{SecureRandom.uuid}",
662662
activities: [activity],
663-
build_id: 'ignore'
664663
)
665664
end
666665
Temporalio::Worker.run_all(*workers) do

temporalio/test/worker_workflow_versioning_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
require 'temporalio/testing'
66
require 'temporalio/worker'
77
require 'temporalio/worker/deployment_options'
8-
require 'temporalio/worker_versioning'
8+
require 'temporalio/worker_deployment_version'
99
require 'temporalio/workflow'
1010
require 'temporalio/workflow/definition'
1111
require 'test'
1212
require 'timeout'
1313

14-
class WorkerWorkflowTest < Test
14+
class WorkerWorkflowVersioningTest < Test
1515
class DeploymentVersioningWorkflowV1AutoUpgrade < Temporalio::Workflow::Definition
1616
workflow_name :DeploymentVersioningWorkflow
1717
workflow_versioning_behavior Temporalio::VersioningBehavior::AUTO_UPGRADE

0 commit comments

Comments
 (0)