Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4c03bf7

Browse files
nagl-stripeGitHub Enterprise
authored and
GitHub Enterprise
committedMar 11, 2022
Merge pull request coinbase#73 from stripe-private-oss-forks/nagl-RUN_WOFLO-310
Expose scheduled_time and current_attempt_scheduled_time on activity metadata
2 parents 7170411 + 33208a7 commit 4c03bf7

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed
 

‎lib/temporal/metadata.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ def generate_activity_metadata(task, namespace)
2121
workflow_id: task.workflow_execution.workflow_id,
2222
workflow_name: task.workflow_type.name,
2323
headers: from_payload_map(task.header&.fields || {}),
24-
heartbeat_details: from_details_payloads(task.heartbeat_details)
24+
heartbeat_details: from_details_payloads(task.heartbeat_details),
25+
# temporal doesn't render sub-second times, so we ignore the nanos field
26+
scheduled_time: task.scheduled_time.seconds,
27+
current_attempt_scheduled_time: task.current_attempt_scheduled_time.seconds
2528
)
2629
end
2730

‎lib/temporal/metadata/activity.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
module Temporal
44
module Metadata
55
class Activity < Base
6-
attr_reader :namespace, :id, :name, :task_token, :attempt, :workflow_run_id, :workflow_id, :workflow_name, :headers, :heartbeat_details
6+
attr_reader :namespace, :id, :name, :task_token, :attempt, :workflow_run_id, :workflow_id, :workflow_name, :headers, :heartbeat_details, :scheduled_time, :current_attempt_scheduled_time
77

8-
def initialize(namespace:, id:, name:, task_token:, attempt:, workflow_run_id:, workflow_id:, workflow_name:, headers: {}, heartbeat_details:)
8+
def initialize(namespace:, id:, name:, task_token:, attempt:, workflow_run_id:, workflow_id:, workflow_name:, headers: {}, heartbeat_details:, scheduled_time:, current_attempt_scheduled_time:)
99
@namespace = namespace
1010
@id = id
1111
@name = name
@@ -16,6 +16,8 @@ def initialize(namespace:, id:, name:, task_token:, attempt:, workflow_run_id:,
1616
@workflow_name = workflow_name
1717
@headers = headers
1818
@heartbeat_details = heartbeat_details
19+
@scheduled_time = scheduled_time
20+
@current_attempt_scheduled_time = current_attempt_scheduled_time
1921

2022
freeze
2123
end
@@ -32,7 +34,9 @@ def to_h
3234
'run_id' => workflow_run_id,
3335
'activity_id' => id,
3436
'activity_name' => name,
35-
'attempt' => attempt
37+
'attempt' => attempt,
38+
'scheduled_time' => scheduled_time,
39+
'current_attempt_scheduled_time' => current_attempt_scheduled_time,
3640
}
3741
end
3842
end

‎lib/temporal/testing/local_workflow_context.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def execute_activity(activity_class, *input, **args)
6060
workflow_id: workflow_id,
6161
workflow_name: self.metadata.name,
6262
headers: execution_options.headers,
63-
heartbeat_details: nil
63+
heartbeat_details: nil,
64+
scheduled_time: Time.now.to_i,
65+
current_attempt_scheduled_time: Time.now.to_i,
6466
)
6567
context = LocalActivityContext.new(metadata)
6668

@@ -110,7 +112,9 @@ def execute_local_activity(activity_class, *input, **args)
110112
workflow_id: workflow_id,
111113
workflow_name: self.metadata.name,
112114
headers: execution_options.headers,
113-
heartbeat_details: nil
115+
heartbeat_details: nil,
116+
scheduled_time: Time.now.to_i,
117+
current_attempt_scheduled_time: Time.now.to_i,
114118
)
115119
context = LocalActivityContext.new(metadata)
116120

‎spec/fabricators/activity_metadata_fabricator.rb

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
workflow_name 'TestWorkflow'
1212
headers { {} }
1313
heartbeat_details nil
14+
scheduled_time 0
15+
current_attempt_scheduled_time 0
1416
end

‎spec/fabricators/grpc/activity_task_fabricator.rb

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
workflow_execution { Fabricate(:api_workflow_execution) }
1212
current_attempt_scheduled_time { Google::Protobuf::Timestamp.new.tap { |t| t.from_time(Time.now) } }
1313
started_time { Google::Protobuf::Timestamp.new.tap { |t| t.from_time(Time.now) } }
14+
scheduled_time { Google::Protobuf::Timestamp.new.tap { |t| t.from_time(Time.now) } }
15+
current_attempt_scheduled_time { Google::Protobuf::Timestamp.new.tap { |t| t.from_time(Time.now) } }
1416
header do |attrs|
1517
fields = (attrs[:headers] || {}).each_with_object({}) do |(field, value), h|
1618
h[field] = Temporal.configuration.converter.to_payload(value)

‎spec/unit/lib/temporal/metadata/activity_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
expect(subject.workflow_name).to eq(args.workflow_name)
1717
expect(subject.headers).to eq(args.headers)
1818
expect(subject.heartbeat_details).to eq(args.heartbeat_details)
19+
expect(subject.scheduled_time).to eq(args.scheduled_time)
20+
expect(subject.current_attempt_scheduled_time).to eq(args.current_attempt_scheduled_time)
1921
end
2022

2123
it { is_expected.to be_frozen }
@@ -36,7 +38,9 @@
3638
'namespace' => subject.namespace,
3739
'workflow_id' => subject.workflow_id,
3840
'workflow_name' => subject.workflow_name,
39-
'run_id' => subject.workflow_run_id
41+
'run_id' => subject.workflow_run_id,
42+
'scheduled_time' => subject.scheduled_time,
43+
'current_attempt_scheduled_time' => subject.current_attempt_scheduled_time,
4044
})
4145
end
4246
end

‎spec/unit/lib/temporal/testing/temporal_override_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def execute
196196
expect(metadata.namespace).to eq('default-namespace')
197197
expect(metadata.workflow_id).to eq(workflow_id)
198198
expect(metadata.workflow_run_id).to eq(run_id)
199+
expect(metadata.scheduled_time).to be > 0
200+
expect(metadata.current_attempt_scheduled_time).to be > 0
199201
end
200202

201203
describe 'execution control' do

0 commit comments

Comments
 (0)
Please sign in to comment.