Class: Localjob::Worker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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), **options)
  @channel, @logger = Channel.new(queues), logger
  @options = options
  @shutdown = false
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



3
4
5
# File 'lib/localjob/worker.rb', line 3

def channel
  @channel
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/localjob/worker.rb', line 3

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/localjob/worker.rb', line 4

def options
  @options
end

Instance Method Details

#pidObject



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

#workObject



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(@options[:pid_file])
  deamonize if @options[:deamon]
  loop { shift_and_process }
end