美文网首页
Sidekiq 的启动与重启

Sidekiq 的启动与重启

作者: bruce_wu | 来源:发表于2020-05-12 09:04 被阅读0次
    image.png
    # Usage: bundle exec rake sidekiq:restart RAILS_ENV=<environment name>
    
    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..."
        system "bundle exec sidekiq -e production -C config/sidekiq.yml -P tmp/pids/sidekiq.pid -d -L log/sidekiq.log" # starts sidekiq process here
        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
    

    更多sidekiq操作见这里:https://github.com/mperham/sidekiq/wiki/API#retries,可以清除重试的任务

    相关文章

      网友评论

          本文标题:Sidekiq 的启动与重启

          本文链接:https://www.haomeiwen.com/subject/lquvnhtx.html