Class: Q4m::Queue::Job
- Inherits:
-
Object
- Object
- Q4m::Queue::Job
- Defined in:
- lib/q4m.rb
Instance Method Summary collapse
-
#initialize(mysql, log) ⇒ Job
constructor
Job initializer.
-
#run ⇒ Object
Job runner.
-
#shutdown ⇒ Object
Shuts down the worker.
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
#run ⇒ Object
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 |
#shutdown ⇒ Object
Shuts down the worker
38 39 40 41 42 |
# File 'lib/q4m.rb', line 38 def shutdown @mysql.close @log.close nil end |