class Belated::Worker
The worker class that actually gets the jobs from the queue and calls them. Expects the jobs to be procs or classes that have a perform method.
Public Class Methods
new(number: 1)
click to toggle source
# File lib/belated/worker.rb, line 11 def initialize(number: 1) @number = number start_working end
Public Instance Methods
start_working()
click to toggle source
# File lib/belated/worker.rb, line 16 def start_working loop do log "Worker #{@number} fetching jobs!" next unless (job = Belated.fetch_job) break if job.is_a?(Symbol) log "Worker #{@number} got job: #{job.inspect}" log job.perform history_insert(job) unless job.proc_klass || !job.completed rescue DRb::DRbConnError, Errno::ECONNREFUSED, RangeError => e log e end end
Private Instance Methods
history_insert(job)
click to toggle source
# File lib/belated/worker.rb, line 33 def history_insert(job) store.transaction do store[job.id] = job end rescue StandardError => e error e end
store()
click to toggle source
# File lib/belated/worker.rb, line 41 def store today = Time.now.strftime('%F') return @store if @store&.path&.include?(today) @store = PStore.new("history_#{Belated.environment}-#{today}.pstore", true) end