# rufus-scheduler
[![Build Status](https://secure.travis-ci.org/jmettraux/rufus-scheduler.png)](http://travis-ci.org/jmettraux/rufus-scheduler)
[![Gem Version](https://badge.fury.io/rb/rufus-scheduler.png)](http://badge.fury.io/rb/rufus-scheduler)
Job scheduler for Ruby (at, cron, in and every jobs).
**Note**: maybe are you looking for the [README of rufus-scheduler 2.x](https://github.com/jmettraux/rufus-scheduler/blob/two/README.rdoc)?
Quickstart:
```ruby
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
scheduler.in '3s' do
puts 'Hello... Rufus'
end
scheduler.join
# let the current thread join the scheduler thread
```
Various forms of scheduling are supported:
```ruby
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
# ...
scheduler.in '10d' do
# do something in 10 days
end
scheduler.at '2030/12/12 23:30:00' do
# do something at a given point in time
end
scheduler.every '3h' do
# do something every 3 hours
end
scheduler.cron '5 0 * * *' do
# do something every day, five minutes after midnight
# (see "man 5 crontab" in your terminal)
end
# ...
```
## non-features
Rufus-scheduler (out of the box) is an in-process, in-memory scheduler.
It does not persist your schedules. When the process is gone and the scheduler instance with it, the schedules are gone.
## related and similar gems
* [whenever](https://github.com/javan/whenever) - let cron call back your Ruby code, trusted and reliable cron drives your schedule
* [clockwork](https://github.com/tomykaira/clockwork) - rufus-scheduler inspired gem
(please note: rufus-scheduler is not a cron replacement)
## note about the 3.0 line
It's a complete rewrite of rufus-scheduler.
There is no EventMachine-based scheduler anymore.
## Notables changes:
* As said, no more EventMachine-based scheduler
* ```scheduler.every('100') {``` will schedule every 100 seconds (previously, it would have been 0.1s). This aligns rufus-scheduler on Ruby's ```sleep(100)```
* The scheduler isn't catching the whole of Exception anymore, only StandardError
* The error_handler is #on_error (instead of #on_exception), by default it now prints the details of the error to $stderr (used to be $stdout)
* Rufus::Scheduler::TimeOutError renamed to Rufus::Scheduler::TimeoutError
* Introduction of "interval" jobs. Whereas "every" jobs are like "every 10 minutes, do this", interval jobs are like "do that, then wait for 10 minutes, then do that again, and so on"
* Introduction of a :lockfile => true/filename mechanism to prevent multiple schedulers from executing
* "discard_past" is on by default. If the scheduler (its host) sleeps for 1 hour and a ```every '10m'``` job is on, it will trigger once at wakeup, not 6 times (discard_past was false by default in rufus-scheduler 2.x). No intention to re-introduce ```:discard_past => false``` in 3.0 for now.
* Introduction of Scheduler #on_pre_trigger and #on_post_trigger callback points
## getting help
So you need help. People can help you, but first help them help you, and don't waste their time. Provide a complete description of the issue. If it works on A but not on B and others have to ask you: "so what is different between A and B" you are wasting everyone's time.
"hello" and "thanks" are not swear words.
Go read [how to report bugs effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html), twice.
Update: [help_help.md](https://gist.github.com/jmettraux/310fed75f568fd731814) might help help you.
### on StackOverflow
Use this [form](http://stackoverflow.com/questions/ask?tags=rufus-scheduler+ruby). It'll create a question flagged "rufus-scheduler" and "ruby".
Here are the [questions tagged rufus-scheduler](http://stackoverflow.com/questions/tagged/rufus-scheduler).
### on IRC
I sometimes haunt #ruote on freenode.net. The channel is not dedicated to rufus-scheduler, so if you ask a question, first mention it's about rufus-scheduler.
Please note that I prefer helping over Stack Overflow because it's more searchable than the ruote IRC archive.
### issues
Yes, issues can be reported in [rufus-scheduler issues](https://github.com/jmettraux/rufus-scheduler/issues), I'd actually prefer bugs in there. If there is nothing wrong with rufus-scheduler, a [Stack Overflow question](http://stackoverflow.com/questions/ask?tags=rufus-scheduler+ruby) is better.
### faq
* [It doesn't work...](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html)
* [I want a refund](http://blog.nodejitsu.com/getting-refunds-on-open-source-projects)
* [Passenger and rufus-scheduler](http://stackoverflow.com/questions/18108719/debugging-rufus-scheduler/18156180#18156180)
* [Passenger and rufus-scheduler (2)](http://stackoverflow.com/questions/21861387/rufus-cron-job-not-working-in-apache-passenger#answer-21868555)
* [Unicorn and rufus-scheduler](https://jkraemer.net/running-rufus-scheduler-in-a-unicorn-rails-app)
## scheduling
Rufus-scheduler supports five kinds of jobs. in, at, every, interval and cron jobs.
Most of the rufus-scheduler examples show block scheduling, but it's also OK to schedule handler instances or handler classes.
### in, at, every, interval, cron
In and at jobs trigger once.
```ruby
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
scheduler.in '10d' do
puts "10 days reminder for review X!"
end
scheduler.at '2014/12/24 2000' do
puts "merry xmas!"
end
```
In jobs are scheduled with a time interval, they trigger after that time elapsed. At jobs are scheduled with a point in time, they trigger when that point in time is reached (better to choose a point in the future).
Every, interval and cron jobs trigger repeatedly.
```ruby
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
scheduler.every '3h' do
puts "change the oil filter!"
end
scheduler.interval '2h' do
puts "thinking..."
puts sleep(rand * 1000)
puts "thought."
end
scheduler.cron '00 09 * * *' do
puts "it's 9am! good morning!"
end
```
Every jobs try hard to trigger following the frequency they were scheduled with.
Interval jobs, trigger, execute and then trigger again after the interval elapsed. (every jobs time between trigger times, interval jobs time between trigger termination and the next trigger start).
Cron jobs are based on the venerable cron utility (```man 5 crontab```). They trigger following a pattern given in (almost) the same language cron uses.
### #schedule_x vs #x
schedule_in, schedule_at, schedule_cron, etc will return the new Job instance.
in, at, cron will return the new Job instance's id (a String).
```ruby
job_id =
scheduler.in '10d' do
# ...
end
job = scheduler.job(job_id)
# versus
job =
scheduler.schedule_in '10d' do
# ...
end
# also
job =
scheduler.in '10d', :job => true do
# ...
end
```
### #schedule and #repeat
Sometimes it pays to be less verbose.
The ```#schedule``` methods schedules an at, in or cron job. It just decide based on its input. It returns the Job instance.
```ruby
scheduler.schedule '10d' do; end.class
# => Rufus::Scheduler::InJob
scheduler.schedule '2013/12/12 12:30' do; end.class
# => Rufus::Scheduler::AtJob
scheduler.schedule '* * * * *' do; end.class
# => Rufus::Scheduler::CronJob
```
The ```#repeat``` method schedules and returns an EveryJob or a CronJob.
```ruby
scheduler.repeat '10d' do; end.class
# => Rufus::Scheduler::EveryJob
scheduler.repeat '* * * * *' do; end.class
# => Rufus::Scheduler::CronJob
```
(Yes, no combination heres gives back an IntervalJob).
### schedule blocks arguments (job, time)
A schedule block may be given 0, 1 or 2 arguments.
The first argument is "job", it's simple the Job instance involved. It might be useful if the job is to be unscheduled for some reason.
```ruby
scheduler.every '10m' do |job|
status = determine_pie_status
if status == 'burnt' || status == 'cooked'
stop_oven
takeout_pie
job.unschedule
end
end
```
The second argument is "time", it's the time when the job g
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Logstash 2.4.1 (2000个子文件)
1fe462c2.0 904B
tt.1 2KB
gemfile.5 19KB
libjffi-1.2.a 143KB
add_owner 25B
add_web_hook 63B
admin 463B
Amsterdam 3KB
Andorra 2KB
LICENSE.ant 3KB
api_key 32B
Appraisals 1KB
ast 6KB
AUTHORS 1KB
AUTHORS 1KB
aws 1KB
aws-rb 4KB
aws-rb 506B
bacula 5KB
bad_robots 17KB
jruby.bash 11KB
gen_requires.bash 834B
setup.bat 3KB
logstash.bat 689B
logstash-plugin.bat 251B
rspec.bat 245B
jrubyd.bat 245B
plugin.bat 203B
jruby.bat 125B
jirb_swing.bat 47B
jrubyc.bat 43B
testrb.bat 43B
jgem.bat 41B
rdoc.bat 41B
jirb.bat 41B
rake.bat 41B
ast.bat 40B
irb.bat 40B
gem.bat 40B
ri.bat 39B
testDirectory.bin 303B
binary 26KB
bootstrap 47B
LICENSE.bouncycastle 1KB
bro 2KB
BSDL 1KB
LICENCE.bsf 3KB
Buenos_Aires 1KB
build_all 944B
bundle 3KB
bundle 599B
bundle 583B
bundle-config 9KB
bundle-exec 6KB
bundle-install 16KB
bundle-package 3KB
bundle-platform 1KB
bundle-update 8KB
bundle_ruby 1KB
bundler 598B
bundler 584B
test.c 88KB
test.c 76KB
http_parser.c 60KB
http_parser.c 57KB
xml_node.c 41KB
http11_parser.c 24KB
ng.c 20KB
xml_document.c 15KB
ruby_http_parser.c 14KB
xml_reader.c 14KB
puma_http11.c 13KB
xml_node_set.c 12KB
hitimes_interval.c 10KB
mini_ssl.c 9KB
xml_sax_parser.c 8KB
xml_xpath_context.c 8KB
xslt_stylesheet.c 7KB
hitimes_stats.c 6KB
html_element_description.c 6KB
xml_sax_parser_context.c 6KB
xml_schema.c 4KB
html_document.c 4KB
nokogiri.c 4KB
xml_dtd.c 4KB
atomic_reference.c 4KB
xml_relax_ng.c 4KB
io_buffer.c 3KB
html_sax_parser_context.c 3KB
xml_libxml2_hacks.c 3KB
xml_sax_push_parser.c 3KB
xml_entity_decl.c 3KB
xml_element_content.c 3KB
xml_namespace.c 3KB
html_sax_push_parser.c 2KB
xml_attr.c 2KB
xml_syntax_error.c 2KB
xml_encoding_handler.c 2KB
xml_comment.c 2KB
xml_attribute_decl.c 1KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- ziseningjing2019-10-22感谢大神分享
- nanFei01102017-11-20比一些新版本的兼容性要好
- laochenggangbadei2018-09-11不错的资源
- IgorZ2018-07-18酷!~外网下不来。。。只好求助csdn
CherryAndJeff
- 粉丝: 6
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功