Sha256: 67c681d42f2ffaa4540ed942ef4b909dec1d2999ee7e27a792382f9f9da567ad

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

if File.exists?(ROOT + '/config/initializers/resque.rb')
  require ROOT + '/config/initializers/resque.rb'
  require 'resque/tasks'
  if defined?(Resque::Scheduler)
    require 'resque_scheduler/tasks'
  end
  namespace :resque do
    task :setup => :environment

    task :_work => ['resque:preload', 'resque:setup'] do
      work = Resque::Worker.new('*')
      Process.daemon(true)
      File.open(ROOT + '/tmp/resque.pid', 'w') { |f| f << work.pid }
      work.work(5)
    end

    if defined?(Resque::Scheduler)
      task :_scheduler => 'resque:setup' do
        Process.daemon(true)
        File.open(ROOT + '/tmp/scheduler.pid', 'w') { |f| f << Process.pid.to_s }
        Resque::Scheduler.run
      end
    end

    desc 'Start Resque daemon worker'
    task :start => 'resque:stop' do
      sys "bash -c 'RAILS_ENV=production rake resque:_work'"
      if defined?(Resque::Scheduler)
        sys "bash -c 'RAILS_ENV=production rake resque:_scheduler'"
      end
    end

    desc 'Stop Resque worker'
    task :stop do
      ['resque', 'scheduler'].each do |name|
        path = ROOT + '/tmp/' + name + '.pid'
        if File.exists?(path)
          sys "kill `cat #{path}`;rm #{path}"
        end
      end
    end

    desc 'Clear Resque data'
    task :clear do
      Resque.redis.keys('*').each{ |k| Resque.redis.del k }
    end

    desc 'Start Resque web interface'
    task :web do
      require 'resque/server'
      Resque::Server.run!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zfben_rails_rake-0.0.18 lib/zfben_rails_rake/tasks/resque.rb