Module: ResqueScheduler

Defined in:
lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.farm_statusObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb', line 38

def self.farm_status
  status = {}
  if Rails.env =~ /development|test/
    status['localhost'] = pids.present? ? 'Running' : 'Stopped'
  else
    Resque.schedule.values.collect{|job| job['ip']}.each do |ip|
      cap = `cd #{Rails.root}; #{ResqueUi::Cap.path} #{Rails.env} resque:scheduler_status hosts=#{ip}`
      status[ip] = cap =~ /resque:scheduler is up/ ? 'Running' : 'Stopped'
    end
  end
  status
end

.pidsObject

Returns an array of string pids of all the other workers on this machine. Useful when pruning dead workers on startup.



53
54
55
56
57
# File 'lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb', line 53

def self.pids
  `ps -A -o pid,command | grep [r]esque:scheduler`.split("\n").map do |line|
    line.split(' ')[0]
  end
end

.quit(ips) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb', line 25

def self.quit(ips)
  if Rails.env =~ /development|test/
    system("rake resque:quit_scheduler")
  else
    system("cd #{Rails.root}; #{ResqueUi::Cap.path} #{Rails.env} resque:quit_scheduler host=#{ips}")
  end
end

.restart(ips) ⇒ Object



33
34
35
36
# File 'lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb', line 33

def self.restart(ips)
  quit(ips)
  start(ips)
end

.start(ips) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb', line 17

def self.start(ips)
  if Rails.env =~ /development|test/
    Thread.new{system("rake resque:scheduler")}
  else
    Thread.new(ips){|ip_list|system("cd #{Rails.root}; #{ResqueUi::Cap.path} #{Rails.env} resque:scheduler host=#{ip_list}")}
  end
end

Instance Method Details

#scheduleObject

Returns the schedule hash



7
8
9
10
11
12
13
14
15
# File 'lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb', line 7

def schedule
  #the scheduler gem expects a hash, but it's now stored in
  #redis as an array.
  hash = {}
  Resque.list_range(:scheduled, 0, -0).each do |job|
    hash.merge! job
  end
  hash
end

#schedule=(schedule_hash) ⇒ Object



2
3
4
# File 'lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb', line 2

def schedule=(schedule_hash)
  raise 'not implemented'
end