Skip to content

Commit

Permalink
Add started_time to activity metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffschoner committed May 9, 2023
1 parent c9e7e38 commit aaa69bf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/temporal/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def generate_activity_metadata(task, namespace)
workflow_name: task.workflow_type.name,
headers: from_payload_map(task.header&.fields || {}),
heartbeat_details: from_details_payloads(task.heartbeat_details),
started_at: task.started_time.to_time,
scheduled_at: task.scheduled_time.to_time,
current_attempt_scheduled_at: task.current_attempt_scheduled_time.to_time,
start_to_close_timeout: task.start_to_close_timeout.seconds
Expand Down
10 changes: 8 additions & 2 deletions lib/temporal/metadata/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
module Temporal
module Metadata
class Activity < Base
attr_reader :namespace, :id, :name, :task_token, :attempt, :workflow_run_id, :workflow_id, :workflow_name, :headers, :heartbeat_details, :scheduled_at, :current_attempt_scheduled_at, :start_to_close_timeout
attr_reader :namespace, :id, :name, :task_token, :attempt, :workflow_run_id, :workflow_id, :workflow_name,
:heartbeat_details, :started_at, :scheduled_at, :current_attempt_scheduled_at,
:start_to_close_timeout, :headers

def initialize(namespace:, id:, name:, task_token:, attempt:, workflow_run_id:, workflow_id:, workflow_name:, headers: {}, heartbeat_details:, scheduled_at:, current_attempt_scheduled_at:, start_to_close_timeout:)
def initialize(namespace:, id:, name:, task_token:, attempt:, workflow_run_id:, workflow_id:, workflow_name:,
heartbeat_details:, started_at:, scheduled_at:, current_attempt_scheduled_at:,
start_to_close_timeout:, headers: {})
@namespace = namespace
@id = id
@name = name
Expand All @@ -16,6 +20,7 @@ def initialize(namespace:, id:, name:, task_token:, attempt:, workflow_run_id:,
@workflow_name = workflow_name
@headers = headers
@heartbeat_details = heartbeat_details
@started_at = started_at
@scheduled_at = scheduled_at
@current_attempt_scheduled_at = current_attempt_scheduled_at
@start_to_close_timeout = start_to_close_timeout
Expand All @@ -36,6 +41,7 @@ def to_h
'activity_id' => id,
'activity_name' => name,
'attempt' => attempt,
'started_at' => started_at.to_s,
'scheduled_at' => scheduled_at.to_s,
'current_attempt_scheduled_at' => current_attempt_scheduled_at.to_s,
}
Expand Down
2 changes: 2 additions & 0 deletions lib/temporal/testing/local_workflow_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def execute_activity(activity_class, *input, **args)
workflow_name: self.metadata.name,
headers: execution_options.headers,
heartbeat_details: nil,
started_at: Time.now,
scheduled_at: Time.now,
current_attempt_scheduled_at: Time.now,
start_to_close_timeout: 0
Expand Down Expand Up @@ -112,6 +113,7 @@ def execute_local_activity(activity_class, *input, **args)
workflow_name: self.metadata.name,
headers: execution_options.headers,
heartbeat_details: nil,
started_at: Time.now,
scheduled_at: Time.now,
current_attempt_scheduled_at: Time.now,
start_to_close_timeout: 0
Expand Down
1 change: 1 addition & 0 deletions spec/fabricators/activity_metadata_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
workflow_name 'TestWorkflow'
headers { {} }
heartbeat_details nil
started_at { Time.now }
scheduled_at { Time.now }
current_attempt_scheduled_at { Time.now }
start_to_close_timeout 0
Expand Down
2 changes: 2 additions & 0 deletions spec/unit/lib/temporal/metadata/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
expect(subject.workflow_name).to eq(args.workflow_name)
expect(subject.headers).to eq(args.headers)
expect(subject.heartbeat_details).to eq(args.heartbeat_details)
expect(subject.started_at).to eq(args.started_at)
expect(subject.scheduled_at).to eq(args.scheduled_at)
expect(subject.current_attempt_scheduled_at).to eq(args.current_attempt_scheduled_at)
end
Expand All @@ -39,6 +40,7 @@
'workflow_id' => subject.workflow_id,
'workflow_name' => subject.workflow_name,
'workflow_run_id' => subject.workflow_run_id,
'started_at' => subject.started_at.to_s,
'scheduled_at' => subject.scheduled_at.to_s,
'current_attempt_scheduled_at' => subject.current_attempt_scheduled_at.to_s,
})
Expand Down

0 comments on commit aaa69bf

Please sign in to comment.