其他分享
首页 > 其他分享> > sidekiq安装及使用

sidekiq安装及使用

作者:互联网

参考:https://github.com/mperham/sidekiq/wiki/Getting-Started

https://wdxtub.com/2016/07/06/sidekiq-guide/

使用sidekiq之前需要安装redis:参考redis安装

gem 'sidekiq'

rails g sidekiq:worker Hard # will create app/workers/hard_worker.rb

class HardWorker
  include Sidekiq::Worker
   def perform(name, count)
    sleep 10
   1000.times do |index|
     puts "XX#{index}"
   end
   end
  end
end

启动sidekiq:bundle exec sidekiq,启动之后sidekiq会自动监听本地的6379redis的默认端口,在生产环境下需要单独配置,参考https://wdxtub.com/2016/07/06/sidekiq-guide/

调用

1可通过rails c

HardWorker.perform_async

2在需要调用的controll或model中直接

HardWorker.perform_async

在启动sidekiq的终端处会看到打印输出的信息

sikdekiq 运维终端UI
gem 'sinatra', :require => nil

routes.rb中添加

require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'

http://localhost:3000/sidekiq

 

标签:end,perform,安装,sidekiq,https,使用,com,HardWorker
来源: https://www.cnblogs.com/znsongshu/p/10349774.html