From e93d80bda2cc80a36f2a0a66e7d660c425de1e85 Mon Sep 17 00:00:00 2001 From: carlcortright Date: Thu, 2 Apr 2020 21:23:51 -0700 Subject: [PATCH 1/3] unique activity idem --- .gitignore | 3 +++ lib/cadence/workflow/context.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ee919347..e853a217 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ _yardoc/ # rspec failure tracking .rspec_status + +# editors +.idea/* \ No newline at end of file diff --git a/lib/cadence/workflow/context.rb b/lib/cadence/workflow/context.rb index d4dc52b6..cf4d389b 100644 --- a/lib/cadence/workflow/context.rb +++ b/lib/cadence/workflow/context.rb @@ -35,7 +35,7 @@ def execute_activity(activity_class, *input, **args) execution_options = ExecutionOptions.new(activity_class, options) decision = Decision::ScheduleActivity.new( - activity_id: options[:activity_id], + activity_id: UUID.v5(activity_class.to_s, input.to_s + args.to_s), activity_type: execution_options.name, input: input, domain: execution_options.domain, From 1f7289ee84a37abbd8093eae232aa930418fa30c Mon Sep 17 00:00:00 2001 From: carlcortright Date: Thu, 2 Apr 2020 21:28:54 -0700 Subject: [PATCH 2/3] update to use run_id when generating uuid --- lib/cadence/workflow/context.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cadence/workflow/context.rb b/lib/cadence/workflow/context.rb index cf4d389b..f6382b7d 100644 --- a/lib/cadence/workflow/context.rb +++ b/lib/cadence/workflow/context.rb @@ -35,7 +35,7 @@ def execute_activity(activity_class, *input, **args) execution_options = ExecutionOptions.new(activity_class, options) decision = Decision::ScheduleActivity.new( - activity_id: UUID.v5(activity_class.to_s, input.to_s + args.to_s), + activity_id: UUID.v5(metadata.run_id, activity_class.to_s + input.to_s + args.to_s), activity_type: execution_options.name, input: input, domain: execution_options.domain, From 9713eb7da9beb862d6cc1f0f385da8469e48b085 Mon Sep 17 00:00:00 2001 From: carlcortright Date: Mon, 6 Apr 2020 20:26:43 -0700 Subject: [PATCH 3/3] use step in the history to differentiate activities calls with the same params --- lib/cadence/workflow/context.rb | 12 ++++++++++-- lib/cadence/workflow/executor.rb | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/cadence/workflow/context.rb b/lib/cadence/workflow/context.rb index f6382b7d..4d42a673 100644 --- a/lib/cadence/workflow/context.rb +++ b/lib/cadence/workflow/context.rb @@ -12,10 +12,11 @@ module Cadence class Workflow class Context - def initialize(state_manager, dispatcher, metadata) + def initialize(state_manager, dispatcher, metadata, history) @state_manager = state_manager @dispatcher = dispatcher @metadata = metadata + @history = history end def logger @@ -33,9 +34,16 @@ def execute_activity(activity_class, *input, **args) input << args unless args.empty? execution_options = ExecutionOptions.new(activity_class, options) + + # Creates a unique activity id that is idempotent for this activity call in the current + # sequence of decision tasks + idem_activity_id = UUID.v5( + metadata.run_id, + activity_class.to_s + input.to_s + args.to_s + @history.events.length.to_s + ) decision = Decision::ScheduleActivity.new( - activity_id: UUID.v5(metadata.run_id, activity_class.to_s + input.to_s + args.to_s), + activity_id: idem_activity_id, activity_type: execution_options.name, input: input, domain: execution_options.domain, diff --git a/lib/cadence/workflow/executor.rb b/lib/cadence/workflow/executor.rb index e7182203..665e3f1d 100644 --- a/lib/cadence/workflow/executor.rb +++ b/lib/cadence/workflow/executor.rb @@ -35,7 +35,7 @@ def run attr_reader :workflow_class, :dispatcher, :state_manager, :history, :new_decisions def execute_workflow(input, metadata) - context = Workflow::Context.new(state_manager, dispatcher, metadata) + context = Workflow::Context.new(state_manager, dispatcher, metadata, history) Fiber.new do workflow_class.execute_in_context(context, input)