Sha256: 29aa9783da93bb5b31b45239c4444517d158b34a5db44cefff2136e6c118e369

Contents?: true

Size: 1.49 KB

Versions: 51

Compression:

Stored size: 1.49 KB

Contents

# require 'resque/tasks'
# will give you the resque tasks

namespace :resque do
  task :setup

  desc "Start a Resque worker"
  task :work => [ :preload, :setup ] do
    require 'resque'

    queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')

    begin
      worker = Resque::Worker.new(*queues)
      worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
      worker.very_verbose = ENV['VVERBOSE']
    rescue Resque::NoQueueError
      abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
    end

    if ENV['BACKGROUND']
      unless Process.respond_to?('daemon')
          abort "env var BACKGROUND is set, which requires ruby >= 1.9"
      end
      Process.daemon(true)
    end

    if ENV['PIDFILE']
      File.open(ENV['PIDFILE'], 'w') { |f| f << worker.pid }
    end

    worker.log "Starting worker #{worker}"

    worker.work(ENV['INTERVAL'] || 5) # interval, will block
  end

  desc "Start multiple Resque workers. Should only be used in dev mode."
  task :workers do
    threads = []

    ENV['COUNT'].to_i.times do
      threads << Thread.new do
        system "rake resque:work"
      end
    end

    threads.each { |thread| thread.join }
  end

  # Preload app files if this is Rails
  task :preload => :setup do
    if defined?(Rails) && Rails.respond_to?(:application)
      # Rails 3
      Rails.application.eager_load!
    elsif defined?(Rails::Initializer)
      # Rails 2.3
      $rails_rake_task = false
      Rails::Initializer.run :load_application_classes
    end
  end
end

Version data entries

51 entries across 51 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.7.4 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.7.3 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.7.2 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.7.1 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.7.0 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.9 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.8 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.7 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.6 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.5 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.4 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.3 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.2 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.1 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.6.0 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.5.17 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.5.16 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.5.15 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb
classiccms-0.5.14 vendor/bundle/gems/resque-1.20.0/lib/resque/tasks.rb