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.
-
#heartbeat(*details) ⇒ Object
Record a heartbeat on the activity.
-
#info ⇒ Info
Activity info for this activity.
-
#logger ⇒ ScopedLogger
Logger for this activity.
-
#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.
63 64 65 |
# File 'lib/temporalio/activity/context.rb', line 63 def cancellation 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.
58 59 60 |
# File 'lib/temporalio/activity/context.rb', line 58 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 |
#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.
81 82 83 |
# File 'lib/temporalio/activity/context.rb', line 81 def logger raise NotImplementedError end |
#payload_converter ⇒ Converters::PayloadConverter
Returns Payload converter associated with this activity.
74 75 76 |
# File 'lib/temporalio/activity/context.rb', line 74 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.
69 70 71 |
# File 'lib/temporalio/activity/context.rb', line 69 def worker_shutdown_cancellation raise NotImplementedError end |