Class: Qyu::Workers::Sync

Inherits:
Base
  • Object
show all
Defined in:
lib/qyu/workers/sync.rb

Overview

Qyu::Workers::Sync

Instance Attribute Summary

Attributes inherited from Base

#id, #processed_tasks

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Concerns::Timeout

#timeout

Methods included from Concerns::PayloadValidator

#validate_payload!, #validates

Methods included from Concerns::FailureQueue

#failure_queue

Methods included from Concerns::Callback

#callback, #run_callbacks

Constructor Details

This class inherits a constructor from Qyu::Workers::Base

Instance Method Details

#work(queue_name, blocking: true) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/qyu/workers/sync.rb', line 7

def work(queue_name, blocking: true)
  super do |task|
    job = task.job
    task_names_to_wait_for = job.tasks_to_wait_for(task)
    log(:debug, "Task names to wait for: #{task_names_to_wait_for}")
    task_names_to_wait_for.each do |task_name|
      sync_condition = job.sync_condition(task, task_name)
      log(:debug, "Task: #{task_name}, Sync condition: #{sync_condition}")
      if respond_to?(sync_condition['function'], true)
        __send__(sync_condition['function'], job, task, task_name, sync_condition['param'])
        # execute attached sync block only if codition passes (i.e. No errors raised)
        yield(task) if block_given?
      else
        fail Qyu::Errors::NotImplementedError
      end
    end
  end
end