rufus-scheduler 3.0.8 → 3.2.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.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,81 @@
2
2
  = rufus-scheduler CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-scheduler - 3.2.0 released 2015-12-28
6
+
7
+ - cache CronLine#brute_frequency results, gh-188 and gh-89
8
+ - "every" shift prevention by https://github.com/Korrigan
9
+ - Ruby warnings silenced by https://github.com/vivitar
10
+
11
+
12
+ == rufus-scheduler - 3.1.10 released 2015-11-18
13
+
14
+ - allow for :first_in => 0, gh-179 by https://github.com/JonMcPherson
15
+ for https://github.com/Shopify/dashing/commit/ea3730fa4
16
+ - stop shipping specs in gem
17
+
18
+
19
+ == rufus-scheduler - 3.1.9 released 2015-11-12
20
+
21
+ - fix potential RuntimeError in CronLine#prev_second,
22
+ by Alexandru https://github.com/alexandru-calinoiu
23
+
24
+
25
+ == rufus-scheduler - 3.1.8 released 2015-11-10
26
+
27
+ - stop jumping eagerly out of DST, fix for one hour jump when leaving DST
28
+ thanks Alyssa http://github.com/alyssa
29
+
30
+
31
+ == rufus-scheduler - 3.1.7 released 2015-10-15
32
+
33
+ - ack #unscheduled_at in #scheduled?, by Claude https://github.com/claudeatsafe
34
+
35
+
36
+ == rufus-scheduler - 3.1.6 released 2015-10-01
37
+
38
+ - fix job id uniqueness (JRuby), thanks 김성식 https://github.com/kssminus
39
+
40
+
41
+ == rufus-scheduler - 3.1.5 released 2015-09-25
42
+
43
+ - fix for "not a valid cronline" on "mingw" Ruby distributions, gh-166
44
+
45
+
46
+ == rufus-scheduler - 3.1.4 released 2015/08/29
47
+
48
+ - fix cron issue reported by Jesse https://github.com/jhw-at-prosperworks-com
49
+
50
+
51
+ == rufus-scheduler - 3.1.3 released 2015/06/20
52
+
53
+ - prevent Thread[:rufus_scheduler_time] -> nil, gh-156
54
+ - fix inconsistency in Job#start_work_thread
55
+
56
+
57
+ == rufus-scheduler - 3.1.2 released 2015/05/23
58
+
59
+ - avoid cron/:first_at infinite loop, thanks https://github.com/pouellet
60
+
61
+
62
+ == rufus-scheduler - 3.1.1 released 2015/04/19
63
+
64
+ - fix ZoTime.is_timezone? on OSX, thanks https://github.com/yaauie
65
+
66
+
67
+ == rufus-scheduler - 3.1.0 released 2015/04/18
68
+
69
+ - go without tzinfo (and its dependencies)
70
+ - include @ketan's #next_time improvements
71
+ - remove 2.x warning message on install
72
+
73
+
74
+ == rufus-scheduler - 3.0.9 released 2014/08/30
75
+
76
+ - fix TZ with underscores, thanks https://github.com/gnilrets
77
+ - integrate https://github.com/ecin Lock mecha
78
+
79
+
5
80
  == rufus-scheduler - 3.0.8 released 2014/06/09
6
81
 
7
82
  - handle TZInfo errors on DST transitions, thanks https://github.com/junhanamaki
data/CREDITS.txt CHANGED
@@ -4,6 +4,21 @@
4
4
 
5
5
  == Contributors
6
6
 
7
+ - Balasankar C (https://github.com/balasankarc) fix CronJob spec vs December
8
+ - Matthieu Rosinski (https://github.com/Korrigan) prevent "every" shifts
9
+ - vivitar (https://github.com/vivitar) silenced a set of Ruby warnings
10
+ - Jon McPherson (https://github.com/JonMcPherson) :first_in => 0 back
11
+ - Calinoiu Alexandru Nicolae (https://github.com/alexandru-calinoiu) CronLine#prev_second fix
12
+ - Alyssa Pohahau (https://github.com/alyssa) out of DST transition specs
13
+ - Claude Vessaz (https://github.com/claudeatsafe) ack #unscheduled_at in #scheduled?
14
+ - 김성식 (https://github.com/kssminus) job id uniqueness effort
15
+ - Jesse Willet (https://github.com/jhw-at-prosperworks-com) cron vs "*/10"
16
+ - Pascal Ouellet (https://github.com/pouellet) Scheduler#timeline loop fix
17
+ - Ryan Biesemeyer (https://github.com/yaauie) ZoTime.is_timezone? on OSX
18
+ - Ketan Padegaonkar (https://github.com/ketan) .brute_frequency improvement
19
+ - Gabriel Gilder (https://github.com/ggilder) LA DST specs
20
+ - Sterling Paramore (https://github.com/gnilrets) underscore TZ fix
21
+ - ecin (https://github.com/ecin) new lock mecha
7
22
  - Adam Jonas (https://github.com/adamjonas) migrate specs to "expect"
8
23
  - Yassen Bantchev (https://github.com/yassenb) CronLine#previous_time rewrite
9
24
  - Eric Lindvall (https://github.com/eric) Zookeeper locked example
@@ -31,6 +46,12 @@
31
46
 
32
47
  == Feedback
33
48
 
49
+ - Eduardo Maia - https://github.com/emaiax - rufus and the Rails console
50
+ - Suisea - https://github.com/suisea - readme rewording
51
+ - Radek - http://stackoverflow.com/users/250422 - gh-166
52
+ - Patrik Ragnarsson - https://github.com/dentarg - timeout vs nil, gh-156
53
+ - twitter @adefilaedward1 - typo in readme
54
+ - Michael Guymon - https://github.com/mguymon - #next_time vs :first_at
34
55
  - junhanamaki - https://github.com/junhanamaki - #next_time and dst ambiguities
35
56
  - kreynolds (tossrock) - inspiration for #occurrences
36
57
  - Matteo - https://github.com/m4ce - dst and cron issue
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2005-2014, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2005-2015, 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/README.md CHANGED
@@ -61,6 +61,7 @@ It does not persist your schedules. When the process is gone and the scheduler i
61
61
 
62
62
  * [whenever](https://github.com/javan/whenever) - let cron call back your Ruby code, trusted and reliable cron drives your schedule
63
63
  * [clockwork](https://github.com/tomykaira/clockwork) - rufus-scheduler inspired gem
64
+ * [crono](https://github.com/plashchynski/crono) - an in-Rails cron scheduler
64
65
 
65
66
  (please note: rufus-scheduler is not a cron replacement)
66
67
 
@@ -72,7 +73,12 @@ It's a complete rewrite of rufus-scheduler.
72
73
  There is no EventMachine-based scheduler anymore.
73
74
 
74
75
 
75
- ## Notables changes:
76
+ ## I don't know what this Ruby thing is, where are my Rails?
77
+
78
+ I'll drive you right to the [tracks](#so-rails).
79
+
80
+
81
+ ## Notable changes:
76
82
 
77
83
  * As said, no more EventMachine-based scheduler
78
84
  * ```scheduler.every('100') {``` will schedule every 100 seconds (previously, it would have been 0.1s). This aligns rufus-scheduler on Ruby's ```sleep(100)```
@@ -89,6 +95,8 @@ There is no EventMachine-based scheduler anymore.
89
95
 
90
96
  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.
91
97
 
98
+ "hello" and "thanks" are not swear words.
99
+
92
100
  Go read [how to report bugs effectively](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html), twice.
93
101
 
94
102
  Update: [help_help.md](https://gist.github.com/jmettraux/310fed75f568fd731814) might help help you.
@@ -115,7 +123,8 @@ Yes, issues can be reported in [rufus-scheduler issues](https://github.com/jmett
115
123
  * [I want a refund](http://blog.nodejitsu.com/getting-refunds-on-open-source-projects)
116
124
  * [Passenger and rufus-scheduler](http://stackoverflow.com/questions/18108719/debugging-rufus-scheduler/18156180#18156180)
117
125
  * [Passenger and rufus-scheduler (2)](http://stackoverflow.com/questions/21861387/rufus-cron-job-not-working-in-apache-passenger#answer-21868555)
118
- * [Unicorn and rufus-scheduler](https://jkraemer.net/running-rufus-scheduler-in-a-unicorn-rails-app)
126
+ * [The scheduler comes up when running the Rails console](https://github.com/jmettraux/rufus-scheduler#avoid-scheduling-when-running-the-ruby-on-rails-console)
127
+ * [I don't get any of this, I just want it to work in my Rails application](#so-rails)
119
128
 
120
129
 
121
130
  ## scheduling
@@ -1097,6 +1106,57 @@ This is useful in environments where the Ruby process holding the scheduler gets
1097
1106
 
1098
1107
  If the lockfile mechanism here is not sufficient, you can plug your custom mechanism. It's explained in [advanced lock schemes](#advanced-lock-schemes) below.
1099
1108
 
1109
+ ### :scheduler_lock
1110
+
1111
+ (since rufus-scheduler 3.0.9)
1112
+
1113
+ The scheduler lock is an object that responds to `#lock` and `#unlock`. The scheduler calls `#lock` when starting up. If the answer is `false`, the scheduler stops its initialization work and won't schedule anything.
1114
+
1115
+ Here is a sample of a scheduler lock that only lets the scheduler on host "coffee.example.com" start:
1116
+ ```ruby
1117
+ class HostLock
1118
+ def initialize(lock_name)
1119
+ @lock_name = lock_name
1120
+ end
1121
+ def lock
1122
+ @lock_name == `hostname -f`.strip
1123
+ end
1124
+ def unlock
1125
+ true
1126
+ end
1127
+ end
1128
+
1129
+ scheduler =
1130
+ Rufus::Scheduler.new(:scheduler_lock => HostLock.new('coffee.example.com'))
1131
+ ```
1132
+
1133
+ By default, the scheduler_lock is an instance of `Rufus::Scheduler::NullLock`, with a `#lock` that returns true.
1134
+
1135
+ ### :trigger_lock
1136
+
1137
+ (since rufus-scheduler 3.0.9)
1138
+
1139
+ The trigger lock in an object that responds to `#lock`. The scheduler calls that method on the job lock right before triggering any job. If the answer is false, the trigger doesn't happen, the job is not done (at least not in this scheduler).
1140
+
1141
+ Here is a (stupid) PingLock example, it'll only trigger if an "other host" is not responding to ping. Do not use that in production, you don't want to fork a ping process for each trigger attempt...
1142
+ ```ruby
1143
+ class PingLock
1144
+ def initialize(other_host)
1145
+ @other_host = other_host
1146
+ end
1147
+ def lock
1148
+ ! system("ping -c 1 #{@other_host}")
1149
+ end
1150
+ end
1151
+
1152
+ scheduler =
1153
+ Rufus::Scheduler.new(:trigger_lock => PingLock.new('main.example.com'))
1154
+ ```
1155
+
1156
+ By default, the trigger_lock is an instance of `Rufus::Scheduler::NullLock`, with a `#lock` that always returns true.
1157
+
1158
+ As explained in [advanced lock schemes](#advanced-lock-schemes), another way to tune that behaviour is by overriding the scheduler's `#confirm_lock` method. (You could also do that with an `#on_pre_trigger` callback).
1159
+
1100
1160
  ### :max_work_threads
1101
1161
 
1102
1162
  In rufus-scheduler 2.x, by default, each job triggering received its own, brand new, thread of execution. In rufus-scheduler 3.x, execution happens in a pooled work thread. The max work thread count (the pool size) defaults to 28.
@@ -1183,6 +1243,20 @@ to make sure that the lock is still valid.
1183
1243
 
1184
1244
  The #confirm_lock method is called right before a job triggers (if it is provided). The more generic callback #on_pre_trigger is called right after #confirm_lock.
1185
1245
 
1246
+ ### :scheduler_lock and :trigger_lock
1247
+
1248
+ (introduced in rufus-scheduler 3.0.9).
1249
+
1250
+ Another way of prodiving `#lock`, `#unlock` and `#confirm_lock` to a rufus-scheduler is by using the `:scheduler_lock` and `:trigger_lock` options.
1251
+
1252
+ See [:trigger_lock](#trigger_lock) and [:scheduler_lock](#scheduler_lock).
1253
+
1254
+ The scheduler lock may be used to prevent a scheduler from starting, while a trigger lock prevents individual jobs from triggering (the scheduler goes on scheduling).
1255
+
1256
+ One has to be careful with what goes in `#confirm_lock` or in a trigger lock, as it gets called before each trigger.
1257
+
1258
+ Warning: you may think you're heading towards "high availability" by using a trigger lock and having lots of schedulers at hand. It may be so if you limit yourself to scheduling the same set of jobs at scheduler startup. But if you add schedules at runtime, they stay local to their scheduler. There is no magic that propagates the jobs to all the schedulers in your pack.
1259
+
1186
1260
 
1187
1261
  ## parsing cronlines and time strings
1188
1262
 
@@ -1303,19 +1377,6 @@ Rufus::Scheduler.parse("2013-12-12 14:00 Pacific/Saipan")
1303
1377
  # => 2013-12-12 04:00:00 UTC
1304
1378
  ```
1305
1379
 
1306
- Behind the scenes, rufus-scheduler uses [tzinfo](http://tzinfo.github.io/) to deal with timezones.
1307
-
1308
- Here is a [list of timezones](misc/tz_all.txt) known to my Debian GNU/Linux 7. It was generated with this script:
1309
-
1310
- ```ruby
1311
- require 'tzinfo'
1312
- TZInfo::Timezone.all.each { |tz| puts tz.name }
1313
- ```
1314
-
1315
- Unknown timezones, typos, will be rejected by tzinfo thus rufus-scheduler.
1316
-
1317
- On its own tzinfo derives the timezones from the system's information. On some system it needs some help, one can install the 'tzinfo-data' gem to provide the missing information.
1318
-
1319
1380
 
1320
1381
  ## so Rails?
1321
1382
 
@@ -1339,6 +1400,7 @@ s = Rufus::Scheduler.singleton
1339
1400
  s.every '1m' do
1340
1401
 
1341
1402
  Rails.logger.info "hello, it's #{Time.now}"
1403
+ Rails.logger.flush
1342
1404
  end
1343
1405
  ```
1344
1406
 
@@ -1367,6 +1429,49 @@ The rufus-scheduler singleton is instantiated in the ```config/initializers/sche
1367
1429
 
1368
1430
  *Warning*: this works well with single-process Ruby servers like Webrick and Thin. Using rufus-scheduler with Passenger or Unicorn requires a bit more knowledge and tuning, gently provided by a bit of googling and reading, see [Faq](#faq) above.
1369
1431
 
1432
+ ### avoid scheduling when running the Ruby on Rails console
1433
+
1434
+ (Written in reply to https://github.com/jmettraux/rufus-scheduler/issues/186 )
1435
+
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:
1437
+
1438
+ ```ruby
1439
+ #
1440
+ # config/initializers/scheduler.rb
1441
+
1442
+ require 'rufus-scheduler'
1443
+
1444
+ s = Rufus::Scheduler.singleton
1445
+
1446
+
1447
+ unless defined?(Rails::Console)
1448
+ # only schedule when not running from the Rails on Rails console
1449
+
1450
+ s.every '1m' do
1451
+
1452
+ Rails.logger.info "hello, it's #{Time.now}"
1453
+ Rails.logger.flush
1454
+ end
1455
+ end
1456
+ ```
1457
+
1458
+ It should work for Ruby on Rails 3 and 4.
1459
+
1460
+ ### rails server -d
1461
+
1462
+ (Written in reply to https://github.com/jmettraux/rufus-scheduler/issues/165 )
1463
+
1464
+ There is the handy `rails server -d` that starts a development Rails as a daemon. The annoying thing is that the scheduler as seen above is started in the main process that then gets forked and daemonized. The rufus-scheduler thread (and any other thread) gets lost, no scheduling happens.
1465
+
1466
+ I avoid running `-d` in development mode and bother about daemonizing only for production deployment.
1467
+
1468
+ These are two well crafted articles on process daemonization, please read them:
1469
+
1470
+ * http://www.mikeperham.com/2014/09/22/dont-daemonize-your-daemons/
1471
+ * http://www.mikeperham.com/2014/07/07/use-runit/
1472
+
1473
+ If, anyway, you need something like `rails server -d`, why not try `bundle exec unicorn -D` instead? In my (limited) experience, it worked out of the box (well, had to add `gem 'unicorn'` to `Gemfile` first).
1474
+
1370
1475
 
1371
1476
  ## support
1372
1477