Class: Q4m::Queue::Job

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

Instance Method Summary collapse

Constructor Details

#initialize(mysql, log) ⇒ Job

Job initializer.

::mysql

a Mysql instance

::log

a Logger instance



16
17
18
19
# File 'lib/q4m.rb', line 16

def initialize mysql, log
  @mysql, @log = mysql, log
  look_for_jobs!
end

Instance Method Details

#runObject

Job runner.

  • Locks the queue.

  • Executes the latest job.

  • Restores the queue so other worker can execute a process.



27
28
29
30
31
32
33
34
# File 'lib/q4m.rb', line 27

def run
  return unless @has_jobs
  queue_wait
  @log.info("Executing: #{latest_job.inspect}")
  execute latest_job
  queue_end
  nil
end

#shutdownObject

Shuts down the worker



38
39
40
41
42
# File 'lib/q4m.rb', line 38

def shutdown
  @mysql.close
  @log.close
  nil
end