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 wasn't 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的更多相关文章
- basic use of sidekiq (2)
vim Gemfile source "https://rubygems.org" gem "sidekiq"gem 'rack-protection' gem ...
- Atitit HTTP 认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结
Atitit HTTP认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结 1.1. 最广泛使用的是基本验证 ( ...
- Basic Tutorials of Redis(9) -First Edition RedisHelper
After learning the basic opreation of Redis,we should take some time to summarize the usage. And I w ...
- Basic Tutorials of Redis(8) -Transaction
Data play an important part in our project,how can we ensure correctness of the data and prevent the ...
- Basic Tutorials of Redis(7) -Publish and Subscribe
This post is mainly about the publishment and subscription in Redis.I think you may subscribe some o ...
- Basic Tutorials of Redis(6) - List
Redis's List is different from C#'s List,but similar with C#'s LinkedList.Sometimes I confuse with t ...
- Basic Tutorials of Redis(5) - Sorted Set
The last post is mainly about the unsorted set,in this post I will show you the sorted set playing a ...
- Basic Tutorials of Redis(4) -Set
This post will introduce you to some usages of Set in Redis.The Set is a unordered set,it means that ...
- Basic Tutorials of Redis(3) -Hash
When you first saw the name of Hash,what do you think?HashSet,HashTable or other data structs of C#? ...
随机推荐
- 【niubi-job——一个分布式的任务调度框架】----安装教程
niubi-job是什么 niubi-job是LZ耗时三个星期,费尽心血打造的一个具备高可靠性以及水平扩展能力的分布式任务调度框架,采用quartz作为底层的任务调度管理器,zookeeper做集群的 ...
- VMware打卡虚拟机提示“此虚拟机可能已被复制或移动”
使用VMware打开虚拟机时出现下图的页面,我来解释一下这三个选项按钮的区别与作用. "我已移动虚拟机" //表示打开后的虚拟的网卡的mac地址不变,如果复制本地的,同时开 ...
- 学习之路三十五:Android和WCF通信 - 大数据压缩后传输
最近一直在优化项目的性能,就在前几天找到了一些资料,终于有方案了,那就是压缩数据. 一丶前端和后端的压缩和解压缩流程 二丶优点和缺点 优点:①字符串的压缩率能够达到70%-80%左右 ②字符串数量更少 ...
- java设计优化--装饰者模式
装饰者模式拥有一个设计非常巧妙的结构,它可以动态的添加功能.在基本的设计原则中,有一条重要的设计准则就是合成/聚合复用原则.根据该原则的思想,代码复用应该尽可能使用委托,而不是使用继承.因为继承是一种 ...
- 【BZOJ 3732】 Network Kruskal重构树+倍增LCA
Kruskal重构树裸题, Sunshine互测的A题就是Kruskal重构树,我通过互测了解到了这个神奇的东西... 理解起来应该没什么难度吧,但是我的Peaks连WA,,, 省选估计要滚粗了TwT ...
- json2.js的初步学习与了解
json2.js的初步学习与了解,想要学习json的朋友可以参考下. json2.js的初步学习与了解 1.)该js的下载地址是:http://www.json.org/json2.js 2.)在页面 ...
- 【Gym 100947E】Qwerty78 Trip(组合数取模/费马小定理)
从(1,1)到(n,m),每次向右或向下走一步,,不能经过(x,y),求走的方案数取模.可以经过(x,y)则相当于m+n步里面选n步必须向下走,方案数为 C((m−1)+(n−1),n−1) 再考虑其 ...
- Spring POST
Spring POST+表单对象如果数据格式不正确,则页面直接报400.页面没有反应,烦啊
- SpringMVC中Controller和RestController
项目中的@Controller下有的是返回String类型的(比如getAllBook),有的是void的,当然,String类型是转发的页面,在void中用的是pringwrite,我今天想做一件事 ...
- SQL Server数据库还原:"因为数据库正在使用,所以无法获得对数据库的独占访问权"
如题,网上找了一些客套的方法,如果不想去折腾,请看我的方法: 1.先脱机数据库,这个目的就是为了停掉所有链接 2.选择还原数据库,如果提示日志尾部不完整,请选择数据库属性的选项,覆盖现有数据. 还可以 ...