Sha256: 285b2547b4ad3843928cdd8686f7c6c24b8c3b908a547e3bad0fc74e207be316

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

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

  # Returns the schedule hash
  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

  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

  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

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

  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

  # Returns an array of string pids of all the other workers on this
  # machine. Useful when pruning dead workers on startup.
  def self.pids
    `ps -A -o pid,command | grep [r]esque:scheduler`.split("\n").map do |line|
      line.split(' ')[0]
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
resque_ui-3.2.4 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.2.3 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.2.2 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.2.1 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.2.0 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.7 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.6 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.5 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.4 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.3 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.2 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.1 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.1.0 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb
resque_ui-3.0.0 lib/resque_ui/overrides/resque_scheduler/resque_scheduler.rb