basic use of sidekiq

Posted 冰凌花花~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了basic use of sidekiq相关的知识,希望对你有一定的参考价值。

参考页面

https://github.com/mperham/sidekiq

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

强烈推荐这个视频 

https://www.youtube.com/watch?v=bfPb1zD91Rg&index=1&list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1

 

$mkdir  sidekiq_playground
$cd sidekiq_playground/

$vim Gemfile

添加一个gem

source "https://rubygems.org"

gem "sidekiq"

新增worker.rb

vim worker.rb
require sidekiq

Sidekiq.configure_client do |config|
  config.redis = { db: 1 } 
end

Sidekiq.configure_server do |config|
  config.redis = { db: 1 } 
end

class OurWorker
  include Sidekiq::Worker

  def perform(complexity)
    case complexity
    when "super_hard"
      sleep 20
      puts "super hard! Really took quite a bit of effort"
    when "hard"
      sleep 10
      puts "hard! That was o bit of work"
    else
      sleep 1
      puts "That wasn‘t a lot of effort"
    end 
  end 
end

安装redis,启动sidekiq

$sudo apt-get install redis-server
$ bundle exec sidekiq -r ./worker.rb

执行一下

$ bundle exec irb -r ./worker.rb 
irb(main):001:0> OurWorker.perform_async("easy")
=> "d40dc832d93f50c00afd2ab4"
irb(main):002:0> OurWorker.perform_async("hard")   //立刻执行
=> "33356c6a0c7cd55047d40670"

  irb(main):003:0> OurWorker.perform_in(5,"easy")   //5秒后执行
  => "7a517f4305ff6105aa408b4f"

 

查看启动页面里的输出

$ bundle exec sidekiq -r ./worker.rb
2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: Booting Sidekiq 4.1.1 with redis options {:db=>1, :url=>nil}


         m,
         `$b
    .ss,  $$:         .,d$
    `$$P,d$P    .,md$P"
     ,$$$$$bmmd$$$P^   .d$$$$$$$$$$P   $$^ `"^$$$       ____  _     _      _    _
   $:     ,$$:       / ___|(_) __| | ___| | _(_) __ _
   `b     :$$        \___ \| |/ _` |/ _ \ |/ / |/ _` |
          $$:         ___) | | (_| |  __/   <| | (_| |
          $$         |____/|_|\__,_|\___|_|\_\_|\__, |
        .d$$                                       |_|

2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: Running in ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: See LICENSE and the LGPL-3.0 for licensing details.
2016-03-31T07:11:15.792Z 30945 TID-gnktzwzl4 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2016-03-31T07:11:15.793Z 30945 TID-gnktzwzl4 INFO: Starting processing, hit Ctrl-C to stop
2016-03-31T07:13:17.062Z 30945 TID-gnku2xt9s OurWorker JID-d40dc832d93f50c00afd2ab4 INFO: start
That wasnt a lot of effort
2016-03-31T07:13:18.065Z 30945 TID-gnku2xt9s OurWorker JID-d40dc832d93f50c00afd2ab4 INFO: done: 1.003 sec
2016-03-31T07:14:08.887Z 30945 TID-gnktztls4 OurWorker JID-33356c6a0c7cd55047d40670 INFO: start
hard! That was o bit of work
2016-03-31T07:14:18.887Z 30945 TID-gnktztls4 OurWorker JID-33356c6a0c7cd55047d40670 INFO: done: 10.0 sec

 

以上是关于basic use of sidekiq的主要内容,如果未能解决你的问题,请参考以下文章

[Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def(代码片段

text Visual Basic代码片段

Tracing SQL Queries in Real Time for MySQL Databases using WinDbg and Basic Assembler Knowledge(示例代码

PAT Basic 1049

TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect(代码片段

GitLogon failed, use ctrl+c to cancel basic credential prompt.