Class: Navvy::Worker
- Inherits:
-
Object
- Object
- Navvy::Worker
- Defined in:
- lib/navvy/worker.rb
Class Attribute Summary collapse
-
.sleep_time ⇒ Integer
Sleep time of the worker.
Class Method Summary collapse
-
.fetch_and_run_jobs ⇒ Object
Fetch jobs and run them.
-
.start ⇒ Object
Start the worker.
Class Attribute Details
.sleep_time ⇒ Integer
Sleep time of the worker.
12 13 14 |
# File 'lib/navvy/worker.rb', line 12 def self.sleep_time @sleep_time || Navvy.configuration.sleep_time end |
Class Method Details
.fetch_and_run_jobs ⇒ Object
Fetch jobs and run them.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/navvy/worker.rb', line 39 def self.fetch_and_run_jobs Job.next.each do |job| result = job.run Navvy.logger.colorized_info( "* #{job.object.to_s}.#{job.method_name}" << "(#{job.args.join(', ')}) => #{(job.exception || result).to_s}", job.failed? ? 31 : 32 ) end end |
.start ⇒ Object
Start the worker.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/navvy/worker.rb', line 19 def self.start Navvy.logger.info '*** Starting ***' trap('TERM') { Navvy.logger.info '*** Exiting ***'; $exit = true } trap('INT') { Navvy.logger.info '*** Exiting ***'; $exit = true } loop do fetch_and_run_jobs if $exit Navvy.logger.info '*** Cleaning up ***' Navvy::Job.cleanup break end sleep sleep_time end end |