Class: HardWorker::Worker

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

Overview

The worker class that actually gets the jobs from the queue and calls them. Expects the jobs to be procs.

Instance Method Summary collapse

Constructor Details

#initializeWorker

Returns a new instance of Worker.



5
6
7
# File 'lib/hard_worker/worker.rb', line 5

def initialize
  start_working
end

Instance Method Details

#call_job(job) ⇒ Object



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

def call_job(job)
  if job.respond_to?(:call)
    pp job.call
  else
    pp job&.perform
  end
end

#start_workingObject



9
10
11
12
13
14
15
16
17
# File 'lib/hard_worker/worker.rb', line 9

def start_working
  loop do
    job = HardWorker.fetch_job
    next unless job

    call_job(job)
    puts 'fetching jobs...'
  end
end