Skip to content

Commit 387eb27

Browse files
pr feedback
1 parent 6ee8a3a commit 387eb27

7 files changed

Lines changed: 76 additions & 9 deletions

File tree

patching/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ As expected, this will output "Query result for id deprecated-id: post-patch".
109109
## Stage 4
110110

111111
Once we know we don't even have any workflows running on "Stage 2" or before (i.e. the workflow with the patch with both code paths), we can just remove the patch deprecation altogether.
112-
To use the patch complete workflow, stop the workflow from before and start it again with:
112+
To use the patch complete workflow, stop the worker from before and start it again with:
113113

114114
```bash
115115
bundle exec ruby worker.rb complete
@@ -139,4 +139,3 @@ And if we execute a query against the latest workflow:
139139
As expected, this will output "Query result for id complete-id: post-patch".
140140

141141
Following these stages, we have successfully altered our workflow code.
142-

patching/starter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
when 'start'
1414
# Start a workflow with the given id
1515
client.start_workflow(
16-
'MyWorkflow',
16+
:MyWorkflow,
1717
id: workflow_id,
1818
task_queue: 'patching-sample'
1919
)

patching/workflow_1_initial.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module Patching
77
class MyWorkflow1Initial < Temporalio::Workflow::Definition
8-
workflow_name 'MyWorkflow'
8+
workflow_name :MyWorkflow
99
workflow_query_attr_reader :result
1010

1111
def execute

patching/workflow_2_patched.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
module Patching
77
class MyWorkflow2Patched < Temporalio::Workflow::Definition
8-
workflow_name 'MyWorkflow'
8+
workflow_name :MyWorkflow
99
workflow_query_attr_reader :result
1010

1111
def execute
1212
# Decide which activity to use based on workflow's patch status
13-
@result = if Temporalio::Workflow.patched :my_patch
13+
@result = if Temporalio::Workflow.patched(:my_patch)
1414
Temporalio::Workflow.execute_activity(
1515
MyActivities::PostPatch,
1616
start_to_close_timeout: 5 * 60

patching/workflow_3_deprecated.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
module Patching
77
class MyWorkflow3Deprecated < Temporalio::Workflow::Definition
8-
workflow_name 'MyWorkflow'
8+
workflow_name :MyWorkflow
99
workflow_query_attr_reader :result
1010

1111
def execute
12-
Temporalio::Workflow.deprecate_patch :my_patch
12+
Temporalio::Workflow.deprecate_patch(:my_patch)
1313
@result = Temporalio::Workflow.execute_activity(
1414
MyActivities::PostPatch,
1515
start_to_close_timeout: 5 * 60

patching/workflow_4_complete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module Patching
77
class MyWorkflow4Complete < Temporalio::Workflow::Definition
8-
workflow_name 'MyWorkflow'
8+
workflow_name :MyWorkflow
99
workflow_query_attr_reader :result
1010

1111
def execute

test/patching/my_workflow_test.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# frozen_string_literal: true
2+
3+
require 'test'
4+
require 'patching/my_activities'
5+
require 'patching/workflow_1_initial'
6+
require 'patching/workflow_2_patched'
7+
require 'patching/workflow_3_deprecated'
8+
require 'patching/workflow_4_complete'
9+
10+
require 'securerandom'
11+
require 'temporalio/client'
12+
require 'temporalio/testing'
13+
require 'temporalio/worker'
14+
15+
module Patching
16+
class PatchingWorkflowTest < Test
17+
def setup
18+
@task_queue = "tq-#{SecureRandom.uuid}"
19+
end
20+
21+
def with_handle(env, workflow, id)
22+
Temporalio::Worker.new(
23+
client: env.client,
24+
activities: [MyActivities::PrePatch, MyActivities::PostPatch],
25+
task_queue: @task_queue,
26+
workflows: [workflow]
27+
).run do
28+
handle = env.client.start_workflow(
29+
:MyWorkflow, id:, task_queue: @task_queue
30+
)
31+
yield handle
32+
end
33+
end
34+
35+
def test_workflow
36+
Temporalio::Testing::WorkflowEnvironment.start_local do |env|
37+
initial_handle = with_handle(env, MyWorkflow1Initial, 'initial-id') do |handle|
38+
handle.result
39+
assert_equal 'pre-patch', handle.query(:result)
40+
handle
41+
end
42+
43+
patched_handle = with_handle(env, MyWorkflow2Patched, 'patched-id') do |handle|
44+
handle.result
45+
assert_equal 'pre-patch', initial_handle.query(:result)
46+
assert_equal 'post-patch', handle.query(:result)
47+
handle
48+
end
49+
50+
deprecated_handle = with_handle(env, MyWorkflow3Deprecated, 'deprecated-id') do |handle|
51+
handle.result
52+
assert_raises(Temporalio::Error::WorkflowQueryFailedError) { initial_handle.query(:result) }
53+
assert_equal 'post-patch', patched_handle.query(:result)
54+
assert_equal 'post-patch', handle.query(:result)
55+
handle
56+
end
57+
58+
with_handle(env, MyWorkflow4Complete, 'deprecated-id') do |complete_handle|
59+
complete_handle.result
60+
assert_raises(Temporalio::Error::WorkflowQueryFailedError) { initial_handle.query(:result) }
61+
assert_raises(Temporalio::Error::WorkflowQueryFailedError) { patched_handle.query(:result) }
62+
assert_equal 'post-patch', deprecated_handle.query(:result)
63+
assert_equal 'post-patch', complete_handle.query(:result)
64+
end
65+
end
66+
end
67+
end
68+
end

0 commit comments

Comments
 (0)