rufus-scheduler 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.txt +24 -0
- data/CREDITS.txt +12 -0
- data/LICENSE.txt +1 -1
- data/Makefile +23 -0
- data/README.md +65 -20
- data/fail18.txt +12 -0
- data/lib/rufus/scheduler/cronline.rb +113 -88
- data/lib/rufus/scheduler/job_array.rb +8 -4
- data/lib/rufus/scheduler/jobs.rb +56 -35
- data/lib/rufus/scheduler/locks.rb +2 -2
- data/lib/rufus/scheduler/util.rb +33 -48
- data/lib/rufus/scheduler/zotime.rb +348 -66
- data/lib/rufus/scheduler.rb +19 -10
- data/pics.txt +15 -0
- data/rufus-scheduler.gemspec +2 -4
- metadata +25 -48
- data/Rakefile +0 -83
- data/lib/rufus/scheduler/zones.rb +0 -175
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f5efdaec8fd127103673241abfcb7a14d9135aef
|
|
4
|
+
data.tar.gz: 95b4b8f72eaea194b946e9b6738fa42b9086fc2a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d511d09f4a9c0deffd90a97005d0824b891a55a92236cf885fde676830960ebbaad407d1a4fd4817b81d20d0f7ef9a504ad35b96a58b7a195e30bae89eda0046
|
|
7
|
+
data.tar.gz: d4da5209b9d01d6a4c861ed022b36971377762ae31ec785d068c0070af3e098e0ff0f6939cd128a96f5752deb74c49daf798a074d6a7557fa80d125f4286dcd5
|
data/CHANGELOG.txt
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
= rufus-scheduler CHANGELOG.txt
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
== rufus-scheduler - 3.3.0 released 2016-11-28
|
|
6
|
+
|
|
7
|
+
- Bring in Piavka's Job#trigger_off_schedule, gh-214
|
|
8
|
+
- Reject "day 0" in cronlines, thanks to Ramon Tayag, https://github.com/ramontayag
|
|
9
|
+
- Move away from ENV['TZ'], thanks to Akinori Musha, https://github.com/knu
|
|
10
|
+
- Fix .parse_to_time vs Date issue, as reported by @nsatragno
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
== rufus-scheduler - 3.2.2 released 2016-08-14
|
|
14
|
+
|
|
15
|
+
- job opt hash preservation, as suggested in gh-212, by https://github.com/d-m-u
|
|
16
|
+
- introduce Job#previous_time
|
|
17
|
+
- countered ActiveRecord 3.2.22 on gh-210, by https://github.com/paulodelgado
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
== rufus-scheduler - 3.2.1 released 2016-05-04
|
|
21
|
+
|
|
22
|
+
- accept '* * * * 5L' (last friday) (equivalent to '* * * * 5#-1')
|
|
23
|
+
- CronLine#to_a (#to_array aliasing to it)
|
|
24
|
+
- simplify .parse_duration (and trim input)
|
|
25
|
+
- raise on "*/0 * * * *", by https://github.com/simook
|
|
26
|
+
- introduce "days to end of month" in cron strings
|
|
27
|
+
|
|
28
|
+
|
|
5
29
|
== rufus-scheduler - 3.2.0 released 2015-12-28
|
|
6
30
|
|
|
7
31
|
- cache CronLine#brute_frequency results, gh-188 and gh-89
|
data/CREDITS.txt
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
== Contributors
|
|
6
6
|
|
|
7
|
+
- Piavka (https://github.com/piavka) - Job#trigger_off_schedule, gh-214
|
|
8
|
+
- Paulo Delgado (https://github.com/paulodelgado) counter ActiveRecord, gh-210
|
|
9
|
+
- Anjali Sharma (https://github.com/anjali-sharma) enhance job#last_time example
|
|
10
|
+
- Kyle Simukka (https://github.com/simook) raise on "*/0 * * * *"
|
|
11
|
+
- Ryan McGeary (https://github.com/rmm5t) svg badges for the readme
|
|
7
12
|
- Balasankar C (https://github.com/balasankarc) fix CronJob spec vs December
|
|
8
13
|
- Matthieu Rosinski (https://github.com/Korrigan) prevent "every" shifts
|
|
9
14
|
- vivitar (https://github.com/vivitar) silenced a set of Ruby warnings
|
|
@@ -46,6 +51,13 @@
|
|
|
46
51
|
|
|
47
52
|
== Feedback
|
|
48
53
|
|
|
54
|
+
- Ramon Tayag - https://github.com/ramontayag - prevent day 0 in cronlines
|
|
55
|
+
- Akinori Musha - https://github.com/knu - ENV['TZ'] setting is harmful
|
|
56
|
+
- Nicolás Satragno - https://twitter.com/nsatragno - parse_to_time vs Date
|
|
57
|
+
- d-m-u duhlmann - https://github.com/d-m-u - job opt hash preservation
|
|
58
|
+
- Anjali Sharma - https://github.com/anjali-sharma - fix typographical error
|
|
59
|
+
- Jonathan Campos - https://github.com/jonbcampos - negative cron day idea
|
|
60
|
+
- Andrey Morskov - https://github.com/accessd - fix typographical error
|
|
49
61
|
- Eduardo Maia - https://github.com/emaiax - rufus and the Rails console
|
|
50
62
|
- Suisea - https://github.com/suisea - readme rewording
|
|
51
63
|
- Radek - http://stackoverflow.com/users/250422 - gh-166
|
data/LICENSE.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
Copyright (c) 2005-
|
|
2
|
+
Copyright (c) 2005-2016, John Mettraux, jmettraux@gmail.com
|
|
3
3
|
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/Makefile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
NAME = \
|
|
3
|
+
$(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
|
|
4
|
+
VERSION = \
|
|
5
|
+
$(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
gemspec_validate:
|
|
9
|
+
@echo "---"
|
|
10
|
+
ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
|
|
11
|
+
@echo "---"
|
|
12
|
+
|
|
13
|
+
name: gemspec_validate
|
|
14
|
+
@echo "$(NAME) $(VERSION)"
|
|
15
|
+
|
|
16
|
+
build: gemspec_validate
|
|
17
|
+
gem build $(NAME).gemspec
|
|
18
|
+
mkdir -p pkg
|
|
19
|
+
mv $(NAME)-$(VERSION).gem pkg/
|
|
20
|
+
|
|
21
|
+
push: build
|
|
22
|
+
gem push pkg/$(NAME)-$(VERSION).gem
|
|
23
|
+
|
data/README.md
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
# rufus-scheduler
|
|
3
3
|
|
|
4
|
-
[](http://travis-ci.org/jmettraux/rufus-scheduler)
|
|
5
|
+
[](http://badge.fury.io/rb/rufus-scheduler)
|
|
6
6
|
|
|
7
7
|
Job scheduler for Ruby (at, cron, in and every jobs).
|
|
8
8
|
|
|
9
|
+
It uses threads.
|
|
10
|
+
|
|
9
11
|
**Note**: maybe are you looking for the [README of rufus-scheduler 2.x](https://github.com/jmettraux/rufus-scheduler/blob/two/README.rdoc)?
|
|
10
12
|
|
|
11
13
|
Quickstart:
|
|
12
14
|
```ruby
|
|
15
|
+
# quickstart.rb
|
|
16
|
+
|
|
13
17
|
require 'rufus-scheduler'
|
|
14
18
|
|
|
15
19
|
scheduler = Rufus::Scheduler.new
|
|
@@ -21,6 +25,7 @@ end
|
|
|
21
25
|
scheduler.join
|
|
22
26
|
# let the current thread join the scheduler thread
|
|
23
27
|
```
|
|
28
|
+
(run with `ruby quickstart.rb`)
|
|
24
29
|
|
|
25
30
|
Various forms of scheduling are supported:
|
|
26
31
|
```ruby
|
|
@@ -52,16 +57,19 @@ end
|
|
|
52
57
|
|
|
53
58
|
## non-features
|
|
54
59
|
|
|
55
|
-
Rufus-scheduler (out of the box) is an in-process, in-memory scheduler.
|
|
60
|
+
Rufus-scheduler (out of the box) is an in-process, in-memory scheduler. It uses threads.
|
|
56
61
|
|
|
57
62
|
It does not persist your schedules. When the process is gone and the scheduler instance with it, the schedules are gone.
|
|
58
63
|
|
|
64
|
+
A rufus-scheduler instance will go on scheduling while it is present among the object in a Ruby process. To make it stop scheduling you have to call its [`#shutdown` method](#schedulershutdown).
|
|
65
|
+
|
|
59
66
|
|
|
60
67
|
## related and similar gems
|
|
61
68
|
|
|
62
|
-
* [
|
|
63
|
-
* [
|
|
64
|
-
* [
|
|
69
|
+
* [Whenever](https://github.com/javan/whenever) - let cron call back your Ruby code, trusted and reliable cron drives your schedule
|
|
70
|
+
* [Clockwork](https://github.com/tomykaira/clockwork) - rufus-scheduler inspired gem
|
|
71
|
+
* [Crono](https://github.com/plashchynski/crono) - an in-Rails cron scheduler
|
|
72
|
+
* [PerfectSched](https://github.com/treasure-data/perfectsched) - highly available distributed cron built on [Sequel](http://sequel.jeremyevans.net) and more
|
|
65
73
|
|
|
66
74
|
(please note: rufus-scheduler is not a cron replacement)
|
|
67
75
|
|
|
@@ -101,12 +109,6 @@ Go read [how to report bugs effectively](http://www.chiark.greenend.org.uk/~sgta
|
|
|
101
109
|
|
|
102
110
|
Update: [help_help.md](https://gist.github.com/jmettraux/310fed75f568fd731814) might help help you.
|
|
103
111
|
|
|
104
|
-
### on StackOverflow
|
|
105
|
-
|
|
106
|
-
Use this [form](http://stackoverflow.com/questions/ask?tags=rufus-scheduler+ruby). It'll create a question flagged "rufus-scheduler" and "ruby".
|
|
107
|
-
|
|
108
|
-
Here are the [questions tagged rufus-scheduler](http://stackoverflow.com/questions/tagged/rufus-scheduler).
|
|
109
|
-
|
|
110
112
|
### on IRC
|
|
111
113
|
|
|
112
114
|
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.
|
|
@@ -123,7 +125,9 @@ Yes, issues can be reported in [rufus-scheduler issues](https://github.com/jmett
|
|
|
123
125
|
* [I want a refund](http://blog.nodejitsu.com/getting-refunds-on-open-source-projects)
|
|
124
126
|
* [Passenger and rufus-scheduler](http://stackoverflow.com/questions/18108719/debugging-rufus-scheduler/18156180#18156180)
|
|
125
127
|
* [Passenger and rufus-scheduler (2)](http://stackoverflow.com/questions/21861387/rufus-cron-job-not-working-in-apache-passenger#answer-21868555)
|
|
126
|
-
* [
|
|
128
|
+
* [Passenger in-depth spawn methods](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/)
|
|
129
|
+
* [Passenger in-depth spawn methods (smart spawning)](https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#smart-spawning-hooks)
|
|
130
|
+
* [The scheduler comes up when running the Rails console or a Rake task](https://github.com/jmettraux/rufus-scheduler#avoid-scheduling-when-running-the-ruby-on-rails-console)
|
|
127
131
|
* [I don't get any of this, I just want it to work in my Rails application](#so-rails)
|
|
128
132
|
|
|
129
133
|
|
|
@@ -181,6 +185,8 @@ Interval jobs, trigger, execute and then trigger again after the interval elapse
|
|
|
181
185
|
|
|
182
186
|
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.
|
|
183
187
|
|
|
188
|
+
####
|
|
189
|
+
|
|
184
190
|
### #schedule_x vs #x
|
|
185
191
|
|
|
186
192
|
schedule_in, schedule_at, schedule_cron, etc will return the new Job instance.
|
|
@@ -369,6 +375,8 @@ Since, by default, jobs are triggered in their own new thread, job instances mig
|
|
|
369
375
|
|
|
370
376
|
To prevent overlap, one can set :overlap => false. Such a job will not trigger if one of its instance is already running.
|
|
371
377
|
|
|
378
|
+
The `:overlap` option is considered before the `:mutex` option when the scheduler is reviewing jobs for triggering.
|
|
379
|
+
|
|
372
380
|
### :mutex => mutex_instance / mutex_name / array of mutexes
|
|
373
381
|
|
|
374
382
|
When a job with a mutex triggers, the job's block is executed with the mutex around it, preventing other jobs with the same mutex to enter (it makes the other jobs wait until it exits the mutex).
|
|
@@ -381,6 +389,8 @@ Array of mutexes: original idea and implementation by [Rainux Luo](https://githu
|
|
|
381
389
|
|
|
382
390
|
Warning: creating lots of different mutexes is OK. Rufus-scheduler will place them in its Scheduler#mutexes hash... And they won't get garbage collected.
|
|
383
391
|
|
|
392
|
+
The `:overlap` option is considered before the `:mutex` option when the scheduler is reviewing jobs for triggering.
|
|
393
|
+
|
|
384
394
|
### :timeout => duration or point in time
|
|
385
395
|
|
|
386
396
|
It's OK to specify a timeout when scheduling some work. After the time specified, it gets interrupted via a Rufus::Scheduler::TimeoutError.
|
|
@@ -639,12 +649,31 @@ job.scheduled_at
|
|
|
639
649
|
### last_time
|
|
640
650
|
|
|
641
651
|
Returns the last time the job triggered (is usually nil for AtJob and InJob).
|
|
642
|
-
k
|
|
643
652
|
```ruby
|
|
644
|
-
job = scheduler.schedule_every('
|
|
645
|
-
|
|
653
|
+
job = scheduler.schedule_every('10s') do; end
|
|
654
|
+
|
|
646
655
|
job.scheduled_at
|
|
647
656
|
# => 2013-07-17 23:48:54 +0900
|
|
657
|
+
job.last_time
|
|
658
|
+
# => nil (since we've just scheduled it)
|
|
659
|
+
|
|
660
|
+
# after 10 seconds
|
|
661
|
+
|
|
662
|
+
job.scheduled_at
|
|
663
|
+
# => 2013-07-17 23:48:54 +0900 (same as above)
|
|
664
|
+
job.last_time
|
|
665
|
+
# => 2013-07-17 23:49:04 +0900
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
### previous_time
|
|
669
|
+
|
|
670
|
+
Returns the previous `#next_time`
|
|
671
|
+
```ruby
|
|
672
|
+
scheduler.every('10s') do |job|
|
|
673
|
+
puts "job scheduled for #{job.previous_time} triggered at #{Time.now}"
|
|
674
|
+
puts "next time will be around #{job.next_time}"
|
|
675
|
+
puts "."
|
|
676
|
+
end
|
|
648
677
|
```
|
|
649
678
|
|
|
650
679
|
### last_work_time, mean_work_time
|
|
@@ -1348,7 +1377,6 @@ Rufus::Scheduler.parse('* * * * mon#1').next_time
|
|
|
1348
1377
|
L can be used in the "day" slot:
|
|
1349
1378
|
|
|
1350
1379
|
In this example, the cronline is supposed to trigger every last day of the month at noon:
|
|
1351
|
-
|
|
1352
1380
|
```ruby
|
|
1353
1381
|
require 'rufus-scheduler'
|
|
1354
1382
|
Time.now
|
|
@@ -1357,6 +1385,21 @@ Rufus::Scheduler.parse('00 12 L * *').next_time
|
|
|
1357
1385
|
# => 2013-10-31 12:00:00 +0900
|
|
1358
1386
|
```
|
|
1359
1387
|
|
|
1388
|
+
#### negative day (x days before the end of the month)
|
|
1389
|
+
|
|
1390
|
+
It's OK to pass negative values in the "day" slot:
|
|
1391
|
+
```ruby
|
|
1392
|
+
scheduler.cron '0 0 -5 * *' do
|
|
1393
|
+
# do it at 00h00 5 days before the end of the month...
|
|
1394
|
+
end
|
|
1395
|
+
```
|
|
1396
|
+
|
|
1397
|
+
Negative ranges (`-10--5-`: 10 days before the end of the month to 5 days before the end of the month) are OK, but mixed positive / negative ranges will raise an `ArgumentError`.
|
|
1398
|
+
|
|
1399
|
+
Negative ranges with increments (`-10---2/2`) are accepted as well.
|
|
1400
|
+
|
|
1401
|
+
Descending day ranges are not accepted (`10-8` or `-8--10` for example).
|
|
1402
|
+
|
|
1360
1403
|
|
|
1361
1404
|
## a note about timezones
|
|
1362
1405
|
|
|
@@ -1433,7 +1476,7 @@ The rufus-scheduler singleton is instantiated in the ```config/initializers/sche
|
|
|
1433
1476
|
|
|
1434
1477
|
(Written in reply to https://github.com/jmettraux/rufus-scheduler/issues/186 )
|
|
1435
1478
|
|
|
1436
|
-
If you don't want rufus-scheduler to kick in when running the Ruby on Rails console, you can wrap your initializer in a conditional:
|
|
1479
|
+
If you don't want rufus-scheduler to kick in when running the Ruby on Rails console or invoking a rake task, you can wrap your initializer in a conditional:
|
|
1437
1480
|
|
|
1438
1481
|
```ruby
|
|
1439
1482
|
#
|
|
@@ -1444,8 +1487,10 @@ require 'rufus-scheduler'
|
|
|
1444
1487
|
s = Rufus::Scheduler.singleton
|
|
1445
1488
|
|
|
1446
1489
|
|
|
1447
|
-
unless defined?(Rails::Console)
|
|
1448
|
-
|
|
1490
|
+
unless defined?(Rails::Console) || File.split($0).last == 'rake'
|
|
1491
|
+
|
|
1492
|
+
# only schedule when not running from the Ruby on Rails console
|
|
1493
|
+
# or from a rake task
|
|
1449
1494
|
|
|
1450
1495
|
s.every '1m' do
|
|
1451
1496
|
|
data/fail18.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
rspec ./spec/job_spec.rb:640 # Rufus::Scheduler::Job work time #mean_work_time gathers work times and computes the mean
|
|
3
|
+
rspec ./spec/schedule_at_spec.rb:60 # Rufus::Scheduler#at triggers a job
|
|
4
|
+
rspec ./spec/schedule_in_spec.rb:44 # Rufus::Scheduler#in removes the job after execution
|
|
5
|
+
rspec ./spec/scheduler_spec.rb:83 # Rufus::Scheduler a schedule method passes the job to its block when it triggers
|
|
6
|
+
rspec ./spec/scheduler_spec.rb:534 # Rufus::Scheduler#running_jobs(:tag/:tags => x) returns a list of running jobs filtered by tag
|
|
7
|
+
rspec ./spec/scheduler_spec.rb:601 # Rufus::Scheduler#occurrences(time0, time1) respects :times for repeat jobs
|
|
8
|
+
rspec ./spec/scheduler_spec.rb:1019 # Rufus::Scheduler#on_post_trigger is called right after a job triggers
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
determine_id specs are slower... much slower...
|
|
12
|
+
|