Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ _yardoc/

# rspec failure tracking
.rspec_status

# editors
.idea/*
12 changes: 10 additions & 2 deletions lib/cadence/workflow/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Contributor

@antstorm antstorm Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the same issue as using the current implementation of the activity ID — upon restarting the workflow @history.events.length will change.

This solution is also not replay friendly since @history.events.length will change between different re-runs

)

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,
Expand Down
2 changes: 1 addition & 1 deletion lib/cadence/workflow/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down