Skip to content

Commit e3006f1

Browse files
committed
Added option to set local activity summary. Added activity summary tests
1 parent 1aa91a2 commit e3006f1

File tree

8 files changed

+49
-4
lines changed

8 files changed

+49
-4
lines changed

temporalio/lib/temporalio/internal/worker/workflow_instance/context.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def execute_activity(
130130
def execute_local_activity(
131131
activity,
132132
*args,
133+
summary:,
133134
schedule_to_close_timeout:,
134135
schedule_to_start_timeout:,
135136
start_to_close_timeout:,
@@ -157,6 +158,7 @@ def execute_local_activity(
157158
Temporalio::Worker::Interceptor::Workflow::ExecuteLocalActivityInput.new(
158159
activity:,
159160
args:,
161+
summary:,
160162
schedule_to_close_timeout:,
161163
schedule_to_start_timeout:,
162164
start_to_close_timeout:,

temporalio/lib/temporalio/internal/worker/workflow_instance/outbound_implementation.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def execute_local_activity(input)
114114
local_retry_threshold: ProtoUtils.seconds_to_duration(input.local_retry_threshold),
115115
attempt: do_backoff&.attempt || 0,
116116
original_schedule_time: do_backoff&.original_schedule_time
117-
)
117+
),
118+
user_metadata: ProtoUtils.to_user_metadata(input.summary, nil, @instance.payload_converter)
118119
)
119120
)
120121
seq

temporalio/lib/temporalio/worker/interceptor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def handle_update(input)
228228
ExecuteLocalActivityInput = Data.define(
229229
:activity,
230230
:args,
231+
:summary,
231232
:schedule_to_close_timeout,
232233
:schedule_to_start_timeout,
233234
:start_to_close_timeout,

temporalio/lib/temporalio/workflow.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,16 @@ def self.execute_child_workflow(
208208
#
209209
# @param activity [Class<Activity::Definition>, Symbol, String] Activity definition class or name.
210210
# @param args [Array<Object>] Arguments to the activity.
211+
# @param summary [String, nil] Single-line summary for this activity that may appear in CLI/UI. This can be in
212+
# single-line Temporal markdown format. This is currently experimental.
211213
# @param schedule_to_close_timeout [Float, nil] Max amount of time the activity can take from first being scheduled
212214
# to being completed before it times out. This is inclusive of all retries.
213215
# @param schedule_to_start_timeout [Float, nil] Max amount of time the activity can take to be started from first
214216
# being scheduled.
215217
# @param start_to_close_timeout [Float, nil] Max amount of time a single activity run can take from when it starts
216218
# to when it completes. This is per retry.
217-
# @param retry_policy [RetryPolicy] How an activity is retried on failure. If unset, a server-defined default is
218-
# used. Set maximum attempts to 1 to disable retries.
219+
# @param retry_policy [RetryPolicy, nil] How an activity is retried on failure. If unset, a default policy is used.
220+
# Set maximum attempts to 1 to disable retries.
219221
# @param local_retry_threshold [Float, nil] If the activity is retrying and backoff would exceed this value, a timer
220222
# is scheduled and the activity is retried after. Otherwise, backoff will happen internally within the task.
221223
# Defaults to 1 minute.
@@ -238,6 +240,7 @@ def self.execute_child_workflow(
238240
def self.execute_local_activity(
239241
activity,
240242
*args,
243+
summary: nil,
241244
schedule_to_close_timeout: nil,
242245
schedule_to_start_timeout: nil,
243246
start_to_close_timeout: nil,
@@ -251,7 +254,7 @@ def self.execute_local_activity(
251254
)
252255
_current.execute_local_activity(
253256
activity, *args,
254-
schedule_to_close_timeout:, schedule_to_start_timeout:, start_to_close_timeout:,
257+
summary:, schedule_to_close_timeout:, schedule_to_start_timeout:, start_to_close_timeout:,
255258
retry_policy:, local_retry_threshold:, cancellation:, cancellation_type:,
256259
activity_id:, arg_hints:, result_hint:
257260
)

temporalio/sig/temporalio/internal/worker/workflow_instance/context.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module Temporalio
4848
def execute_local_activity: (
4949
singleton(Activity::Definition) | Symbol | String activity,
5050
*Object? args,
51+
summary: String?,
5152
schedule_to_close_timeout: duration?,
5253
schedule_to_start_timeout: duration?,
5354
start_to_close_timeout: duration?,

temporalio/sig/temporalio/worker/interceptor.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ module Temporalio
175175
class ExecuteLocalActivityInput
176176
attr_reader activity: String
177177
attr_reader args: Array[Object?]
178+
attr_reader summary: String?
178179
attr_reader schedule_to_close_timeout: duration?
179180
attr_reader schedule_to_start_timeout: duration?
180181
attr_reader start_to_close_timeout: duration?
@@ -190,6 +191,7 @@ module Temporalio
190191
def initialize: (
191192
activity: String,
192193
args: Array[Object?],
194+
summary: String?,
193195
schedule_to_close_timeout: duration?,
194196
schedule_to_start_timeout: duration?,
195197
start_to_close_timeout: duration?,

temporalio/sig/temporalio/workflow.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module Temporalio
6262
def self.execute_local_activity: (
6363
singleton(Activity::Definition) | Symbol | String activity,
6464
*Object? args,
65+
?summary: String?,
6566
?schedule_to_close_timeout: duration?,
6667
?schedule_to_start_timeout: duration?,
6768
?start_to_close_timeout: duration?,

temporalio/test/worker_workflow_activity_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'securerandom'
44
require 'temporalio/client'
5+
require 'temporalio/converters/data_converter'
56
require 'temporalio/testing'
67
require 'temporalio/worker'
78
require 'temporalio/workflow'
@@ -29,6 +30,12 @@ def execute(scenario)
2930
Temporalio::Workflow.execute_local_activity(:SimpleActivity, 'local', start_to_close_timeout: 10)
3031
when :local_string_name
3132
Temporalio::Workflow.execute_local_activity('SimpleActivity', 'local', start_to_close_timeout: 10)
33+
when :remote_with_summary
34+
Temporalio::Workflow.execute_activity(SimpleActivity, 'remote',
35+
start_to_close_timeout: 10, summary: 'remote summary')
36+
when :local_with_summary
37+
Temporalio::Workflow.execute_local_activity(SimpleActivity, 'local',
38+
start_to_close_timeout: 10, summary: 'local summary')
3239
else
3340
raise NotImplementedError
3441
end
@@ -368,4 +375,31 @@ def test_cancellation_reset
368375
assert_equal 'canceled - paused: false, requested: false, reset: true', handle.result
369376
end
370377
end
378+
379+
def test_activity_summary
380+
data_converter = Temporalio::Converters::DataConverter.default
381+
execute_workflow(SimpleWorkflow, :remote_with_summary, activities: [SimpleActivity]) do |handle|
382+
handle.result
383+
activity_events = handle.fetch_history.events
384+
.select { |e| e.event_type == :EVENT_TYPE_ACTIVITY_TASK_SCHEDULED }
385+
assert_equal 1, activity_events.size
386+
assert_equal 'remote summary', data_converter.from_payload(activity_events.first.user_metadata.summary)
387+
assert_nil activity_events.first.user_metadata.details
388+
end
389+
end
390+
391+
def test_local_activity_summary
392+
data_converter = Temporalio::Converters::DataConverter.default
393+
execute_workflow(SimpleWorkflow, :local_with_summary, activities: [SimpleActivity]) do |handle|
394+
handle.result
395+
print handle.fetch_history.events
396+
activity_events = handle.fetch_history.events.select do |e|
397+
e.event_type == :EVENT_TYPE_MARKER_RECORDED &&
398+
e.marker_recorded_event_attributes.marker_name == 'core_local_activity'
399+
end
400+
assert_equal 1, activity_events.size
401+
assert_equal 'local summary', data_converter.from_payload(activity_events.first.user_metadata.summary)
402+
assert_nil activity_events.first.user_metadata.details
403+
end
404+
end
371405
end

0 commit comments

Comments
 (0)