Class: Temporalio::Worker::ActivityRunner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/worker/activity_runner.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The main class for handling activity processing. It is expected to be executed from some threaded or async executor’s context since methods called here might be blocking and this should not affect the main worker reactor.

Instance Method Summary collapse

Constructor Details

#initialize(activity_class, start, task_queue, task_token, worker, converter) ⇒ ActivityRunner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ActivityRunner.



15
16
17
18
19
20
21
22
# File 'lib/temporalio/worker/activity_runner.rb', line 15

def initialize(activity_class, start, task_queue, task_token, worker, converter)
  @activity_class = activity_class
  @start = start
  @task_queue = task_queue
  @task_token = task_token
  @worker = worker
  @converter = converter
end

Instance Method Details

#cancel(reason, by_request:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/temporalio/worker/activity_runner.rb', line 45

def cancel(reason, by_request:)
  context.cancel(reason, by_request: by_request)
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/temporalio/worker/activity_runner.rb', line 24

def run
  activity = activity_class.new(context)
  input = converter.from_payload_array(start.input.to_a)

  result = activity.execute(*input)

  converter.to_payload(result)
rescue StandardError => e
  # Temporal server ignores cancellation failures that were not requested by the server.
  # However within the SDK cancellations are also used during the worker shutdown. In order
  # to provide a seamless handling experience (same error raised within the Activity) we are
  # using the ActivityCancelled error and then swapping it with a CancelledError here.
  #
  # In the future this will be handled by the SDK Core — https://github.com/temporalio/sdk-core/issues/461
  if e.is_a?(Temporalio::Error::ActivityCancelled) && e.by_request?
    e = Temporalio::Error::CancelledError.new(e.message)
  end

  converter.to_failure(e)
end