使用rake,启动/停止/重启 sidekiq

# Usage: bundle exec rake sidekiq:restart RAILS_ENV=

namespace :sidekiq do
  sidekiq_pid_file = Rails.root+'tmp/pids/sidekiq.pid'

  desc "Sidekiq stop"
  task :stop do
    puts "#### Trying to stop Sidekiq Now !!! ####"
    if File.exist?(sidekiq_pid_file)
      puts "Stopping sidekiq now #PID-#{File.readlines(sidekiq_pid_file).first}..."
      system "sidekiqctl stop tmp/pids/sidekiq.pid" # stops sidekiq process here
    else
      puts "--- Sidekiq Not Running !!!"
    end
  end

  desc "Sidekiq start"
  task :start do
    puts "Starting Sidekiq..."
    # starts sidekiq process here
    system "bundle exec sidekiq -e#{Rails.env} -C config/sidekiq.yml -P tmp/pids/sidekiq.pid -d -L log/sidekiq.log"
    sleep(2)
    puts "Sidekiq started #PID-#{File.readlines(sidekiq_pid_file).first}."
  end

  desc "Sidekiq restart"
  task :restart do
    puts "#### Trying to restart Sidekiq Now !!! ####"
    Rake::Task['sidekiq:stop'].invoke
    Rake::Task['sidekiq:start'].invoke
    puts "#### Sidekiq restarted successfully !!! ####"
  end
end

你可能感兴趣的:(使用rake,启动/停止/重启 sidekiq)