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..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: options[:activity_id], + 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)