rufus-scheduler 3.1.10 → 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.
@@ -2,6 +2,13 @@
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
+
5
12
  == rufus-scheduler - 3.1.10 released 2015-11-18
6
13
 
7
14
  - allow for :first_in => 0, gh-179 by https://github.com/JonMcPherson
@@ -4,6 +4,9 @@
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
7
10
  - Jon McPherson (https://github.com/JonMcPherson) :first_in => 0 back
8
11
  - Calinoiu Alexandru Nicolae (https://github.com/alexandru-calinoiu) CronLine#prev_second fix
9
12
  - Alyssa Pohahau (https://github.com/alyssa) out of DST transition specs
@@ -43,6 +46,7 @@
43
46
 
44
47
  == Feedback
45
48
 
49
+ - Eduardo Maia - https://github.com/emaiax - rufus and the Rails console
46
50
  - Suisea - https://github.com/suisea - readme rewording
47
51
  - Radek - http://stackoverflow.com/users/250422 - gh-166
48
52
  - Patrik Ragnarsson - https://github.com/dentarg - timeout vs nil, gh-156
data/README.md CHANGED
@@ -123,6 +123,8 @@ Yes, issues can be reported in [rufus-scheduler issues](https://github.com/jmett
123
123
  * [I want a refund](http://blog.nodejitsu.com/getting-refunds-on-open-source-projects)
124
124
  * [Passenger and rufus-scheduler](http://stackoverflow.com/questions/18108719/debugging-rufus-scheduler/18156180#18156180)
125
125
  * [Passenger and rufus-scheduler (2)](http://stackoverflow.com/questions/21861387/rufus-cron-job-not-working-in-apache-passenger#answer-21868555)
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)
126
128
 
127
129
 
128
130
  ## scheduling
@@ -1427,6 +1429,34 @@ The rufus-scheduler singleton is instantiated in the ```config/initializers/sche
1427
1429
 
1428
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.
1429
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
+
1430
1460
  ### rails server -d
1431
1461
 
1432
1462
  (Written in reply to https://github.com/jmettraux/rufus-scheduler/issues/165 )
@@ -39,7 +39,7 @@ module Rufus
39
39
  require 'rufus/scheduler/job_array'
40
40
  require 'rufus/scheduler/locks'
41
41
 
42
- VERSION = '3.1.10'
42
+ VERSION = '3.2.0'
43
43
 
44
44
  #
45
45
  # A common error class for rufus-scheduler
@@ -385,7 +385,7 @@ module Rufus
385
385
  #
386
386
  def scheduled?(job_or_job_id)
387
387
 
388
- job, job_id = fetch(job_or_job_id)
388
+ job, _ = fetch(job_or_job_id)
389
389
 
390
390
  !! (job && job.unscheduled_at.nil? && job.next_time != nil)
391
391
  end
@@ -441,7 +441,7 @@ module Rufus
441
441
  if format == :timeline
442
442
  a = []
443
443
  h.each { |j, ts| ts.each { |t| a << [ t, j ] } }
444
- a.sort_by { |(t, j)| t }
444
+ a.sort_by { |(t, _)| t }
445
445
  else
446
446
  h
447
447
  end
@@ -42,8 +42,8 @@ class Rufus::Scheduler
42
42
  attr_reader :hours
43
43
  attr_reader :days
44
44
  attr_reader :months
45
+ #attr_reader :monthdays # reader defined below
45
46
  attr_reader :weekdays
46
- attr_reader :monthdays
47
47
  attr_reader :timezone
48
48
 
49
49
  def initialize(line)
@@ -223,6 +223,10 @@ class Rufus::Scheduler
223
223
  }[1]
224
224
  end
225
225
 
226
+ # Caching facility. Currently only used for brute frequencies.
227
+ #
228
+ @cache = {}; class << self; attr_reader :cache; end
229
+
226
230
  # Returns the shortest delta between two potential occurences of the
227
231
  # schedule described by this cronline.
228
232
  #
@@ -239,16 +243,13 @@ class Rufus::Scheduler
239
243
  # Of course, this method can get VERY slow if you call on it a second-
240
244
  # based cronline...
241
245
  #
242
- # Since it's a rarely used method, I haven't taken the time to make it
243
- # smarter/faster.
244
- #
245
- # One obvious improvement would be to cache the result once computed...
246
- #
247
- # See https://github.com/jmettraux/rufus-scheduler/issues/89
248
- # for a discussion about this method.
249
- #
250
246
  def brute_frequency
251
247
 
248
+ key = "brute_frequency:#{@original}"
249
+
250
+ delta = self.class.cache[key]
251
+ return delta if delta
252
+
252
253
  delta = 366 * DAY_S
253
254
 
254
255
  t0 = previous_time(Time.local(2000, 1, 1))
@@ -268,7 +269,7 @@ class Rufus::Scheduler
268
269
  t0 = t1
269
270
  end
270
271
 
271
- delta
272
+ self.class.cache[key] = delta
272
273
  end
273
274
 
274
275
  def next_second(time)
@@ -377,7 +378,7 @@ class Rufus::Scheduler
377
378
 
378
379
  return %w[ L ] if item == 'L'
379
380
 
380
- item = '*' + item if item.match(/^\//)
381
+ item = '*' + item if item[0, 1] == '/'
381
382
 
382
383
  m = item.match(RANGE_REGEX)
383
384
 
@@ -391,7 +391,7 @@ module Rufus
391
391
  attr_reader :paused_at
392
392
 
393
393
  attr_reader :first_at
394
- attr_accessor :last_at
394
+ attr_reader :last_at
395
395
  attr_accessor :times
396
396
 
397
397
  def initialize(scheduler, duration, opts, block)
@@ -543,9 +543,12 @@ module Rufus
543
543
 
544
544
  return if is_post
545
545
 
546
+ n = Time.now
547
+
546
548
  @next_time =
547
- if @first_at == nil || @first_at < Time.now
548
- (trigger_time || Time.now) + @frequency
549
+ if @first_at == nil || @first_at < n
550
+ nt = (@next_time || trigger_time || n) + @frequency
551
+ nt > n ? nt : (trigger_time || n) + @frequency
549
552
  else
550
553
  @first_at
551
554
  end
metadata CHANGED
@@ -1,69 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.10
4
+ version: 3.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - John Mettraux
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
12
+ date: 2015-12-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: 2.13.0
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: 2.13.0
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: chronic
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: tzinfo
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - '>='
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - '>='
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0'
69
78
  description: job scheduler for Ruby (at, cron, in and every jobs).
@@ -87,31 +96,31 @@ files:
87
96
  - CHANGELOG.txt
88
97
  - CREDITS.txt
89
98
  - LICENSE.txt
90
- - t.txt
91
99
  - TODO.txt
92
100
  - README.md
93
101
  homepage: http://github.com/jmettraux/rufus-scheduler
94
102
  licenses:
95
103
  - MIT
96
- metadata: {}
97
104
  post_install_message:
98
105
  rdoc_options: []
99
106
  require_paths:
100
107
  - lib
101
108
  required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
102
110
  requirements:
103
- - - '>='
111
+ - - ! '>='
104
112
  - !ruby/object:Gem::Version
105
113
  version: '0'
106
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
107
116
  requirements:
108
- - - '>='
117
+ - - ! '>='
109
118
  - !ruby/object:Gem::Version
110
119
  version: '0'
111
120
  requirements: []
112
121
  rubyforge_project: rufus
113
- rubygems_version: 2.0.14
122
+ rubygems_version: 1.8.23.2
114
123
  signing_key:
115
- specification_version: 4
124
+ specification_version: 3
116
125
  summary: job scheduler for Ruby (at, cron, in and every jobs)
117
126
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 5b6294bd5d0ba45b0ae97cd681c4a915d3f4f15d
4
- data.tar.gz: 1670414782d681e46791acd641524cde44aa8063
5
- SHA512:
6
- metadata.gz: 769cdd5e8e86acb0f4a7dfac068710a0cc12210604604cd7423ea896b9ce2bd68b4f7bd16932c9122577d1121ebc05db7e15af76403e63ff404a60e35d6c96f6
7
- data.tar.gz: cf3b2a402f6bad0411cdba7e9ce8a62021de7cd90bbfb4db321cd3b11b19af28dee9a87c3d1d481957f73a766cd84200a4eaccceb804365003f276876fb798b9
data/t.txt DELETED
@@ -1,31 +0,0 @@
1
-
2
- JRUBY
3
-
4
- 1) Rufus::Scheduler::CronLine fall time correctly decrements every minute through a DST transition
5
-
6
- Failure/Error: expect(points).to eq([
7
-
8
- expected: ["0101-8(0901)", "0100-8(0900)", "0159-7(0859)", "0158-7(0858)"]
9
- got: ["0101-7(0801)", "0100-7(0800)", "0059-7(0759)", "0058-7(0758)"]
10
-
11
- (compared using ==)
12
- # ./spec/cronline_spec.rb:1013:in `(root)'
13
- # ./spec/spec_helper.rb:69:in `in_zone'
14
- # ./spec/cronline_spec.rb:1001:in `(root)'
15
-
16
-
17
- RUBY1.8
18
-
19
- 1) Rufus::Scheduler::CronLine fall time correctly decrements every minute through a DST transition
20
-
21
- Failure/Error: expect(points).to eq([
22
-
23
- expected: ["0101-8(0901)", "0100-8(0900)", "0159-7(0859)", "0158-7(0858)"]
24
- got: ["0101-7(0801)", "0100-7(0800)", "0059-7(0759)", "0058-7(0758)"]
25
-
26
- (compared using ==)
27
- # ./spec/cronline_spec.rb:1013
28
- # ./spec/spec_helper.rb:69:in `call'
29
- # ./spec/spec_helper.rb:69:in `in_zone'
30
- # ./spec/cronline_spec.rb:1001
31
-