whenever 0.6.7 → 0.6.8

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.
@@ -1,3 +1,14 @@
1
+ ### 0.6.8 / May 24th, 2011
2
+
3
+ * Convert most shortcuts to seconds. every :day -> every 1.day. #129 [Javan Makhmali]
4
+
5
+ * Allow commas in raw cron syntax. #130 [Marco Bergantin, Javan Makhmali]
6
+
7
+ * Output no update message as comments. #135 [Javan Makhmali]
8
+
9
+ * require 'thread' to support Rubygems >= 1.6.0. #132 [Javan Makhmali]
10
+
11
+
1
12
  ### 0.6.7 / March 23rd, 2011
2
13
 
3
14
  * Fix issue with comment block being corrupted during subsequent insertion of duplicate entries to the crontab. #123 [Jeremy (@lingmann)]
data/README.md CHANGED
@@ -95,6 +95,13 @@ For example, if you're using bundler do this:
95
95
  set :whenever_command, "bundle exec whenever"
96
96
  require "whenever/capistrano"
97
97
 
98
+ If you are using different environments (such as staging, production), then you may want to do this:
99
+
100
+ set :whenever_environment, defer { stage }
101
+ require "whenever/capistrano"
102
+
103
+ The capistrano variable `:stage` should be the one holding your environment name. This will make the correct `:environment` available in your schedule.rb.
104
+
98
105
  ### The `whenever` command
99
106
 
100
107
  $ cd /my/rails/app
@@ -1,5 +1,6 @@
1
1
  require 'chronic'
2
2
  require 'active_support/all'
3
+ require 'thread'
3
4
 
4
5
  require 'whenever/job_list'
5
6
  require 'whenever/job'
@@ -39,8 +39,8 @@ module Whenever
39
39
  write_crontab(whenever_cron)
40
40
  else
41
41
  puts Whenever.cron(@options)
42
- puts "[message] Above is your schedule file converted to cron syntax; your crontab file was not updated."
43
- puts "[message] Run `whenever --help' for more options."
42
+ puts "## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated."
43
+ puts "## [message] Run `whenever --help' for more options."
44
44
  exit(0)
45
45
  end
46
46
  end
@@ -1,6 +1,7 @@
1
1
  module Whenever
2
2
  module Output
3
3
  class Cron
4
+ REGEX = /^.+ .+ .+ .+ .+.?$/
4
5
 
5
6
  attr_accessor :time, :task
6
7
 
@@ -10,9 +11,14 @@ module Whenever
10
11
  @at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
11
12
  end
12
13
 
13
- def self.enumerate(item)
14
+ def self.enumerate(item, detect_cron = true)
14
15
  if item and item.is_a?(String)
15
- items = item.split(',')
16
+ items =
17
+ if detect_cron && item =~ REGEX
18
+ [item]
19
+ else
20
+ item.split(',')
21
+ end
16
22
  else
17
23
  items = item
18
24
  items = [items] unless items and items.respond_to?(:each)
@@ -22,7 +28,7 @@ module Whenever
22
28
 
23
29
  def self.output(times, job)
24
30
  enumerate(times).each do |time|
25
- enumerate(job.at).each do |at|
31
+ enumerate(job.at, false).each do |at|
26
32
  yield new(time, job.output, at).output
27
33
  end
28
34
  end
@@ -34,7 +40,7 @@ module Whenever
34
40
 
35
41
  def time_in_cron_syntax
36
42
  case @time
37
- when /^.+ .+ .+ .+ .+.?$/ then @time # raw cron sytax given
43
+ when REGEX then @time # raw cron sytax given
38
44
  when Symbol then parse_symbol
39
45
  when String then parse_as_string
40
46
  else parse_time
@@ -45,16 +51,25 @@ module Whenever
45
51
 
46
52
  def parse_symbol
47
53
  shortcut = case @time
48
- when :reboot then '@reboot'
49
- when :year, :yearly then '@annually'
50
- when :day, :daily then '@daily'
51
- when :midnight then '@midnight'
52
- when :month, :monthly then '@monthly'
53
- when :week, :weekly then '@weekly'
54
- when :hour, :hourly then '@hourly'
54
+ when :reboot then '@reboot'
55
+ when :year then 12.months
56
+ when :yearly,
57
+ :annually then '@annually'
58
+ when :day then 1.day
59
+ when :daily then '@daily'
60
+ when :midnight then '@midnight'
61
+ when :month then 1.month
62
+ when :monthly then '@monthly'
63
+ when :week then 1.week
64
+ when :weekly then '@weekly'
65
+ when :hour then 1.hour
66
+ when :hourly then '@hourly'
55
67
  end
56
68
 
57
- if shortcut
69
+ if shortcut.is_a?(Numeric)
70
+ @time = shortcut
71
+ parse_time
72
+ elsif shortcut
58
73
  if @at.is_a?(Time) || (@at.is_a?(Numeric) && @at > 0)
59
74
  raise ArgumentError, "You cannot specify an ':at' when using the shortcuts for times."
60
75
  else
@@ -1,3 +1,3 @@
1
1
  module Whenever
2
- VERSION = '0.6.7'
2
+ VERSION = '0.6.8'
3
3
  end
@@ -166,7 +166,7 @@ class OutputAtTest < Test::Unit::TestCase
166
166
  <<-file
167
167
  set :job_template, nil
168
168
  set :path, '/your/path'
169
- every :day do
169
+ every :daily do
170
170
  rake "blah:blah"
171
171
  runner "runner_1"
172
172
  command "command_1"
@@ -254,14 +254,14 @@ class OutputAtTest < Test::Unit::TestCase
254
254
  @output = Whenever.cron \
255
255
  <<-file
256
256
  set :job_template, nil
257
- every '0 0 27-31 * *' do
257
+ every '0 0 27,31 * *' do
258
258
  command "blahblah"
259
259
  end
260
260
  file
261
261
  end
262
262
 
263
263
  should "output the command using the same cron syntax" do
264
- assert_match '0 0 27-31 * * blahblah', @output
264
+ assert_match '0 0 27,31 * * blahblah', @output
265
265
  end
266
266
  end
267
267
 
@@ -174,20 +174,26 @@ class CronTest < Test::Unit::TestCase
174
174
  context "When parsing time using the cron shortcuts" do
175
175
  should "parse a :symbol into the correct shortcut" do
176
176
  assert_equal '@reboot', parse_time(:reboot)
177
- assert_equal '@annually', parse_time(:year)
177
+ assert_equal '@annually', parse_time(:annually)
178
178
  assert_equal '@annually', parse_time(:yearly)
179
- assert_equal '@daily', parse_time(:day)
180
179
  assert_equal '@daily', parse_time(:daily)
181
180
  assert_equal '@midnight', parse_time(:midnight)
182
- assert_equal '@monthly', parse_time(:month)
183
181
  assert_equal '@monthly', parse_time(:monthly)
184
- assert_equal '@hourly', parse_time(:hour)
182
+ assert_equal '@weekly', parse_time(:weekly)
185
183
  assert_equal '@hourly', parse_time(:hourly)
186
184
  end
187
185
 
186
+ should "convert time-based shortcuts to times" do
187
+ assert_equal '0 0 1 * *', parse_time(:month)
188
+ assert_equal '0 0 * * *', parse_time(:day)
189
+ assert_equal '0 * * * *', parse_time(:hour)
190
+ assert_equal '0 0 1 12 *', parse_time(:year)
191
+ assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
192
+ end
193
+
188
194
  should "raise an exception if a valid shortcut is given but also an :at" do
189
195
  assert_raises ArgumentError do
190
- parse_time(:hour, nil, "1:00 am")
196
+ parse_time(:hourly, nil, "1:00 am")
191
197
  end
192
198
 
193
199
  assert_raises ArgumentError do
@@ -195,7 +201,7 @@ class CronTest < Test::Unit::TestCase
195
201
  end
196
202
 
197
203
  assert_raises ArgumentError do
198
- parse_time(:day, nil, '4:20pm')
204
+ parse_time(:daily, nil, '4:20pm')
199
205
  end
200
206
  end
201
207
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whenever
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 7
10
- version: 0.6.7
9
+ - 8
10
+ version: 0.6.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Javan Makhmali
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-23 00:00:00 -04:00
18
+ date: 2011-05-24 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency