Class: Temporalio::Worker::SyncWorker Private

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/worker/sync_worker.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.

This is a wrapper class for the Core Worker (provided via the Bridge) to abstract away its async nature allowing other modules/classes to interact with it without any callbacks (simplifying the code).

CAUTION: This class will block the thread its running in unless it is used from

within an Async reactor.

Instance Method Summary collapse

Constructor Details

#initialize(core_worker) ⇒ SyncWorker

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 SyncWorker.



15
16
17
# File 'lib/temporalio/worker/sync_worker.rb', line 15

def initialize(core_worker)
  @core_worker = core_worker
end

Instance Method Details

#complete_activity_task_with_cancellation(task_token, failure) ⇒ 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.



43
44
45
46
47
48
49
# File 'lib/temporalio/worker/sync_worker.rb', line 43

def complete_activity_task_with_cancellation(task_token, failure)
  result = Coresdk::ActivityResult::ActivityExecutionResult.new(
    cancelled: Coresdk::ActivityResult::Cancellation.new(failure: failure),
  )

  complete_activity_task(task_token, result)
end

#complete_activity_task_with_failure(task_token, failure) ⇒ 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.



35
36
37
38
39
40
41
# File 'lib/temporalio/worker/sync_worker.rb', line 35

def complete_activity_task_with_failure(task_token, failure)
  result = Coresdk::ActivityResult::ActivityExecutionResult.new(
    failed: Coresdk::ActivityResult::Failure.new(failure: failure),
  )

  complete_activity_task(task_token, result)
end

#complete_activity_task_with_success(task_token, payload) ⇒ 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.



27
28
29
30
31
32
33
# File 'lib/temporalio/worker/sync_worker.rb', line 27

def complete_activity_task_with_success(task_token, payload)
  result = Coresdk::ActivityResult::ActivityExecutionResult.new(
    completed: Coresdk::ActivityResult::Success.new(result: payload),
  )

  complete_activity_task(task_token, result)
end

#poll_activity_taskObject

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.



19
20
21
22
23
24
25
# File 'lib/temporalio/worker/sync_worker.rb', line 19

def poll_activity_task
  with_queue do |done|
    core_worker.poll_activity_task do |task, error|
      done.call(task && Coresdk::ActivityTask::ActivityTask.decode(task), error)
    end
  end
end

#record_activity_heartbeat(task_token, payloads) ⇒ 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.



51
52
53
54
55
56
57
58
59
# File 'lib/temporalio/worker/sync_worker.rb', line 51

def record_activity_heartbeat(task_token, payloads)
  proto = Coresdk::ActivityHeartbeat.new(
    task_token: task_token,
    details: payloads,
  )
  encoded_proto = Coresdk::ActivityHeartbeat.encode(proto)

  core_worker.record_activity_heartbeat(encoded_proto)
end