Class: Localjob::Worker
- Inherits:
-
Object
- Object
- Localjob::Worker
- Defined in:
- lib/localjob/worker.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(queues, logger: Logger.new(STDOUT), **options) ⇒ Worker
constructor
A new instance of Worker.
- #pid ⇒ Object
- #process(job) ⇒ Object
- #work ⇒ Object
Constructor Details
#initialize(queues, logger: Logger.new(STDOUT), **options) ⇒ Worker
Returns a new instance of Worker.
6 7 8 9 10 |
# File 'lib/localjob/worker.rb', line 6 def initialize(queues, logger: Logger.new(STDOUT), **) @channel, @logger = Channel.new(queues), logger = @shutdown = false end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
3 4 5 |
# File 'lib/localjob/worker.rb', line 3 def channel @channel end |
#logger ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/localjob/worker.rb', line 3 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/localjob/worker.rb', line 4 def end |
Instance Method Details
#pid ⇒ Object
17 18 19 |
# File 'lib/localjob/worker.rb', line 17 def pid Process.pid end |
#process(job) ⇒ Object
12 13 14 15 |
# File 'lib/localjob/worker.rb', line 12 def process(job) logger.info "Worker #{pid}: #{job.inspect}" job.perform end |
#work ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/localjob/worker.rb', line 21 def work logger.info "Worker #{pid} now listening!" trap_signals create_pid_file([:pid_file]) deamonize if [:deamon] loop { shift_and_process } end |