Module: Funktor::Worker::ClassMethods

Defined in:
lib/funktor/worker.rb,
lib/funktor/testing.rb

Instance Method Summary collapse

Instance Method Details

#build_job_payload(job_time, *worker_params) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/funktor/worker.rb', line 35

def build_job_payload(job_time, *worker_params)
  {
    worker: self.name,
    worker_params: worker_params,
    queue: self.work_queue,
    incoming_job_queue_url: self.queue_url,
    perform_at: job_time.utc,
    funktor_options: get_funktor_options
  }
end

#clearObject



16
17
18
# File 'lib/funktor/testing.rb', line 16

def clear
  jobs.clear
end

#jobsObject



12
13
14
# File 'lib/funktor/testing.rb', line 12

def jobs
  Funktor::FakeJobQueue.jobs[self.name]
end

#perform_async(*worker_params) ⇒ Object



17
18
19
# File 'lib/funktor/worker.rb', line 17

def perform_async(*worker_params)
  self.perform_in(0, *worker_params)
end

#perform_at(job_time, *worker_params) ⇒ Object



21
22
23
# File 'lib/funktor/worker.rb', line 21

def perform_at(job_time, *worker_params)
  self.push(job_time, *worker_params)
end

#perform_in(delay, *worker_params) ⇒ Object



25
26
27
28
# File 'lib/funktor/worker.rb', line 25

def perform_in(delay, *worker_params)
  job_time = Time.now.utc + delay
  self.perform_at(job_time, *worker_params)
end

#push(job_time, *worker_params) ⇒ Object



30
31
32
33
# File 'lib/funktor/worker.rb', line 30

def push(job_time, *worker_params)
  payload = build_job_payload(job_time, *worker_params)
  Funktor.job_pusher.push(payload)
end

#work_all_jobsObject



20
21
22
23
24
25
26
27
# File 'lib/funktor/testing.rb', line 20

def work_all_jobs
  while jobs.any?
    job_data = jobs.shift.with_indifferent_access
    worker = Object.const_get job_data[:worker]
    worker_params = job_data[:worker_params]
    worker.new.perform(worker_params)
  end
end