Skip to content

Commit 37a2c4f

Browse files
authored
Expose scheduled_time and current_attempt_scheduled_time on activity metadata (#164)
* Expose scheduled_time and current_attempt_scheduled_time on activity metadata * Change field name, use a Time * Fix comment, fix mising .to_time
1 parent e85d401 commit 37a2c4f

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

lib/temporal/metadata.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ 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+
scheduled_at: task.scheduled_time.to_time,
26+
current_attempt_scheduled_at: task.current_attempt_scheduled_time.to_time
2527
)
2628
end
2729

lib/temporal/metadata/activity.rb

Lines changed: 7 additions & 3 deletions
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_at, :current_attempt_scheduled_at
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_at:, current_attempt_scheduled_at:)
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_at = scheduled_at
20+
@current_attempt_scheduled_at = current_attempt_scheduled_at
1921

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

lib/temporal/testing/local_workflow_context.rb

Lines changed: 6 additions & 2 deletions
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: nil, # not yet used, but will be in the future
6262
headers: execution_options.headers,
63-
heartbeat_details: nil
63+
heartbeat_details: nil,
64+
scheduled_at: Time.now,
65+
current_attempt_scheduled_at: Time.now,
6466
)
6567
context = LocalActivityContext.new(metadata)
6668

@@ -108,7 +110,9 @@ def execute_local_activity(activity_class, *input, **args)
108110
workflow_id: workflow_id,
109111
workflow_name: nil, # not yet used, but will be in the future
110112
headers: execution_options.headers,
111-
heartbeat_details: nil
113+
heartbeat_details: nil,
114+
scheduled_at: Time.now,
115+
current_attempt_scheduled_at: Time.now,
112116
)
113117
context = LocalActivityContext.new(metadata)
114118

spec/fabricators/activity_metadata_fabricator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
workflow_name 'TestWorkflow'
1212
headers { {} }
1313
heartbeat_details nil
14+
scheduled_at { Time.now }
15+
current_attempt_scheduled_at { Time.now }
1416
end

spec/fabricators/grpc/activity_task_fabricator.rb

Lines changed: 2 additions & 0 deletions
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

Lines changed: 5 additions & 1 deletion
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_at).to eq(args.scheduled_at)
20+
expect(subject.current_attempt_scheduled_at).to eq(args.current_attempt_scheduled_at)
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-
'workflow_run_id' => subject.workflow_run_id
41+
'workflow_run_id' => subject.workflow_run_id,
42+
'scheduled_at' => subject.scheduled_at.to_s,
43+
'current_attempt_scheduled_at' => subject.current_attempt_scheduled_at.to_s,
4044
})
4145
end
4246
end

0 commit comments

Comments
 (0)