Class: Temporalio::Activity::Context

Inherits:
Object
  • Object
show all
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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentContext

Returns The current context, or raises an error if not in activity fiber/thread.

Returns:

  • (Context)

    The current context, or raises an error if not in activity fiber/thread.

Raises:



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_nilContext?

Returns The current context or nil if not in activity fiber/thread.

Returns:

  • (Context, nil)

    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.

Returns:

  • (Boolean)

    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

#cancellationCancellation

Returns Cancellation that is canceled when the activity is canceled.

Returns:

  • (Cancellation)

    Cancellation that is canceled when the activity is canceled.

Raises:

  • (NotImplementedError)


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.

Parameters:

  • details (Array<Object>)

    Details to record with the heartbeat.

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/temporalio/activity/context.rb', line 58

def heartbeat(*details)
  raise NotImplementedError
end

#infoInfo

Returns Activity info for this activity.

Returns:

  • (Info)

    Activity info for this activity.

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/temporalio/activity/context.rb', line 47

def info
  raise NotImplementedError
end

#loggerScopedLogger

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.

Returns:

  • (ScopedLogger)

    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.

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/temporalio/activity/context.rb', line 81

def logger
  raise NotImplementedError
end

#payload_converterConverters::PayloadConverter

Returns Payload converter associated with this activity.

Returns:

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/temporalio/activity/context.rb', line 74

def payload_converter
  raise NotImplementedError
end

#worker_shutdown_cancellationCancellation

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.

Returns:

  • (Cancellation)

    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.

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/temporalio/activity/context.rb', line 69

def worker_shutdown_cancellation
  raise NotImplementedError
end