Class: Temporalio::Activity::Context
- Inherits:
-
Object
- Object
- Temporalio::Activity::Context
- Defined in:
- lib/temporalio/activity/context.rb
Overview
Context accessible only within an activity. Use Context.current to get the current context. Contexts are fiber or thread local so may not be available in a newly started thread from an activity and may have to be propagated manually.
Direct Known Subclasses
Class Method Summary collapse
-
.current ⇒ Context
The current context, or raises an error if not in activity fiber/thread.
-
.current_or_nil ⇒ Context?
The current context or nil if not in activity fiber/thread.
-
.exist? ⇒ Boolean
Whether there is a current context available.
Instance Method Summary collapse
-
#cancellation ⇒ Cancellation
Cancellation that is canceled when the activity is canceled.
-
#cancellation_details ⇒ CancellationDetails?
Cancellation details if canceled.
-
#client ⇒ Client
Temporal client this activity worker is running in.
-
#heartbeat(*details) ⇒ Object
Record a heartbeat on the activity.
-
#info ⇒ Info
Activity info for this activity.
-
#instance ⇒ Object?
Activity class instance.
-
#logger ⇒ ScopedLogger
Logger for this activity.
-
#metric_meter ⇒ Metric::Meter
Metric meter to create metrics on, with some activity-specific attributes already set.
-
#payload_converter ⇒ Converters::PayloadConverter
Payload converter associated with this activity.
-
#worker_shutdown_cancellation ⇒ Cancellation
Cancellation that is canceled when the worker is shutting down.
Class Method Details
.current ⇒ Context
Returns The current context, or raises an error if not in activity fiber/thread.
11 12 13 14 15 16 |
# File 'lib/temporalio/activity/context.rb', line 11 def self.current context = current_or_nil raise Error, 'Not in activity context' if context.nil? context end |
.current_or_nil ⇒ Context?
Returns The current context or nil if not in activity fiber/thread.
19 20 21 |
# File 'lib/temporalio/activity/context.rb', line 19 def self.current_or_nil _current_executor&.activity_context end |
.exist? ⇒ Boolean
Returns Whether there is a current context available.
24 25 26 |
# File 'lib/temporalio/activity/context.rb', line 24 def self.exist? !current_or_nil.nil? end |
Instance Method Details
#cancellation ⇒ Cancellation
Returns Cancellation that is canceled when the activity is canceled.
69 70 71 |
# File 'lib/temporalio/activity/context.rb', line 69 def cancellation raise NotImplementedError end |
#cancellation_details ⇒ CancellationDetails?
Returns Cancellation details if canceled. These are set just before cancellation is actually canceled. These details only represent when the cancel was first performed. Once set, this object is never mutated. Therefore, the situation on the server may have changed (e.g. unpause), but this still represents the values when cancellation first occurred for this attempt.
77 78 79 |
# File 'lib/temporalio/activity/context.rb', line 77 def cancellation_details raise NotImplementedError end |
#client ⇒ Client
Returns Temporal client this activity worker is running in.
126 127 128 |
# File 'lib/temporalio/activity/context.rb', line 126 def client raise NotImplementedError end |
#heartbeat(*details) ⇒ Object
Record a heartbeat on the activity.
Heartbeats should be used for all non-immediately-returning, non-local activities and they are required to receive cancellation. Heartbeat calls are throttled internally based on the heartbeat timeout of the activity. Users do not have to be concerned with burdening the server by calling this too frequently.
64 65 66 |
# File 'lib/temporalio/activity/context.rb', line 64 def heartbeat(*details) raise NotImplementedError end |
#info ⇒ Info
Returns Activity info for this activity.
47 48 49 |
# File 'lib/temporalio/activity/context.rb', line 47 def info raise NotImplementedError end |
#instance ⇒ Object?
Returns Activity class instance. This should always be present except for advanced cases where the definition was manually created without any instance getter/creator.
53 54 55 |
# File 'lib/temporalio/activity/context.rb', line 53 def instance raise NotImplementedError end |
#logger ⇒ ScopedLogger
Returns Logger for this activity. Note, this is a shared logger not created each activity invocation. It just has logic to extract current activity details and so is only able to do so on log calls made with a current context available.
95 96 97 |
# File 'lib/temporalio/activity/context.rb', line 95 def logger raise NotImplementedError end |
#metric_meter ⇒ Metric::Meter
Returns Metric meter to create metrics on, with some activity-specific attributes already set.
120 121 122 |
# File 'lib/temporalio/activity/context.rb', line 120 def metric_meter raise NotImplementedError end |
#payload_converter ⇒ Converters::PayloadConverter
Returns Payload converter associated with this activity.
88 89 90 |
# File 'lib/temporalio/activity/context.rb', line 88 def payload_converter raise NotImplementedError end |
#worker_shutdown_cancellation ⇒ Cancellation
Returns Cancellation that is canceled when the worker is shutting down. On worker shutdown, this is canceled, then the ‘graceful_shutdown_period` is waited (default 0s), then the activity is canceled.
83 84 85 |
# File 'lib/temporalio/activity/context.rb', line 83 def worker_shutdown_cancellation raise NotImplementedError end |