Class: Delayed::Pool

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Pool

Returns a new instance of Pool.



8
9
10
11
12
13
14
15
# File 'lib/delayed/pool.rb', line 8

def initialize(*args)
  if args.first.is_a?(Hash)
    @config = args.first
  else
    warn "Calling Delayed::Pool.new directly is deprecated. Use `Delayed::CLI.new.run()` instead."
  end
  @workers = {}
end

Instance Attribute Details

#workersObject (readonly)

Returns the value of attribute workers.



6
7
8
# File 'lib/delayed/pool.rb', line 6

def workers
  @workers
end

Instance Method Details

#runObject



17
18
19
20
# File 'lib/delayed/pool.rb', line 17

def run
  warn "Delayed::Pool#run is deprecated and will be removed. Use `Delayed::CLI.new.run()` instead."
  Delayed::CLI.new.run()
end

#startObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/delayed/pool.rb', line 22

def start
  say "Started job master", :info
  $0 = procname
  # fork to handle unlocking (to prevent polluting the parent with worker objects)
  unlock_pid = fork_with_reconnects do
    unlock_orphaned_jobs
  end
  Process.wait unlock_pid

  spawn_periodic_auditor
  spawn_all_workers
  say "Workers spawned"
  join
  say "Shutting down"
rescue Interrupt => e
  say "Signal received, exiting", :info
rescue Exception => e
  say "Job master died with error: #{e.inspect}\n#{e.backtrace.join("\n")}", :fatal
  raise
end