sidekiq强大的异步任务处理_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > sidekiq强大的异步任务处理

sidekiq强大的异步任务处理

 2013/9/14 22:46:17  rain010101  程序员俱乐部  我要评论(0)
  • 摘要:本篇介绍sidekiq基于redis队列的后端的异步任务处理,当然还有定时任务,延时处理等功能。https://github.com/mperham/sidekiq/wikihttp://mperham.github.com/sidekiq/sidekiq的宣传语:Whatif1Sidekiqprocesscoulddotheworkof20ResqueorDelayedJobprocesses?1.定义异步处理worker类app/worker/hard_work
  • 标签:ide 异步
本篇介绍sidekiq基于redis队列的后端的异步任务处理,当然还有定时任务,延时处理等功能。 https://github.com/mperham/sidekiq/wiki http://mperham.github.com/sidekiq/

class="subheader" style="">sidekiq的宣传语:

What if?1?Sidekiq process could do the work of?20?Resque or DelayedJob processes?

1.定义异步处理worker类
? app/worker/hard_work.rb

class HardWorker
      include Sidekiq::Worker
      sidekiq_options :queue => 'phoenix_job' , :timeout => 60, :retry => true, :backtrace => true

      def perform(options,count=5)
          puts 'do'
      end
end
?

2.加载workers目录 ? application.rb

config.autoload_paths += %W(#{Rails.root}/app/workers)
?

3.加入异步任务处理队列
? app/controllers/**_controller.rb

HardWorker.perform_async(params)
?

4.sidekiq.yml配置文件
? config/sidekiq.yml


:verbose: false
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
  - [phoenix_job,7]
  - [default, 2]

staging:
  :concurrency: 5
development:
  :concurrency: 5
production:
  :concurrency: 50
?

5.配置sidekiq链接redis
config/initialiizers/sidekiq.rb
?
      ENV["REDISTOGO_URL"] = "redis://username:.password@host:port}"
?

6.unicorn运行after_fork配置 unicorn.rb

after_fork do |server, worker|

ENV["REDISTOGO_URL"] = "redis://username:.password@host:port}"
?
end


7.运行,停止命令
? stop.sh

bundle exec sidekiqctl quiet tmp/pids/sidekiq.pid
bundle exec sidekiqctl stop tmp/pids/sidekiq.pid
?

start.sh

bundle exec sidekiq  -C config/sidekiq.yml -d -e production
? 感觉比resque好用多了,在断网自动重连,日志文件,pid文件,部署,性能等方面都要好。
发表评论
用户名: 匿名