whenever 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca12a3bcee3b722d97603d4b68c6dbb1a9340bde
4
- data.tar.gz: 4c14d0e96f2fc3e2fff8f4b1d06217184d6d2a5a
3
+ metadata.gz: c96bb55bfcc94c54bab65174a8fb046aa4bfcff1
4
+ data.tar.gz: fbce8b6cd1f6c8558e9281af9f6cbccade7dcd71
5
5
  SHA512:
6
- metadata.gz: 43e5babdecdfe28f925233cf41c04f2caae3b6796c433a30baa265d47c0b82f3d7fe570ee6b84e64ac3e5b4f9e28b252265361c78e24f2699466399ce0d43bde
7
- data.tar.gz: 6ab32597cd5cfc23ee23e16e072589cbfc33fad7da0ac460707fadb60a01b3dc41c28862b8903be785aa588681ecd410e648ddc052ce138f8ec5dddecb990112
6
+ metadata.gz: a23ed3067c55356fb7f98f18d267d508d410cbe63a9ea2dc1f3aaa491bfa6df03cf856ff315a2adb64290cab7fa9348ed486ac362afec8b35583d4efc251eef6
7
+ data.tar.gz: 3e79b8eba708dd80fa79fa8ba80a81205a889f196f6a5a00ee3cdfce82c669ef93e96a10c321cfb4c7cd7fe9addc1ca75860aaa5c082da6ed6400def6c42d575
@@ -3,6 +3,13 @@
3
3
  * Time zone support
4
4
 
5
5
 
6
+ ### 0.8.4 / July 22, 2012
7
+
8
+ * Don't require schedule file when clearing. [Javan Makhmali]
9
+
10
+ * Use bin/rails when available. [Javan Makhmali]
11
+
12
+
6
13
  ### 0.8.3 / July 11, 2013
7
14
 
8
15
  * Improve Cap rollback logic. [Jeroen Jacobs]
@@ -19,7 +19,11 @@ module Whenever
19
19
  Dir.pwd
20
20
  end
21
21
 
22
- def self.rails3?
22
+ def self.bin_rails?
23
+ File.exists?(File.join(path, 'bin', 'rails'))
24
+ end
25
+
26
+ def self.script_rails?
23
27
  File.exists?(File.join(path, 'script', 'rails'))
24
28
  end
25
29
 
@@ -6,15 +6,15 @@ module Whenever
6
6
  def self.execute(options={})
7
7
  new(options).run
8
8
  end
9
-
9
+
10
10
  def initialize(options={})
11
11
  @options = options
12
-
12
+
13
13
  @options[:file] ||= 'config/schedule.rb'
14
14
  @options[:cut] ||= 0
15
15
  @options[:identifier] ||= default_identifier
16
-
17
- unless File.exists?(@options[:file])
16
+
17
+ if !File.exists?(@options[:file]) && @options[:clear].nil?
18
18
  warn("[fail] Can't find file: #{@options[:file]}")
19
19
  exit(1)
20
20
  end
@@ -30,7 +30,7 @@ module Whenever
30
30
  end
31
31
  @options[:cut] = @options[:cut].to_i
32
32
  end
33
-
33
+
34
34
  def run
35
35
  if @options[:update] || @options[:clear]
36
36
  write_crontab(updated_crontab)
@@ -43,28 +43,28 @@ module Whenever
43
43
  exit(0)
44
44
  end
45
45
  end
46
-
46
+
47
47
  protected
48
-
48
+
49
49
  def default_identifier
50
50
  File.expand_path(@options[:file])
51
51
  end
52
-
52
+
53
53
  def whenever_cron
54
54
  return '' if @options[:clear]
55
55
  @whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].compact.join("\n") + "\n"
56
56
  end
57
-
57
+
58
58
  def read_crontab
59
59
  return @current_crontab if @current_crontab
60
-
60
+
61
61
  command = ['crontab -l']
62
62
  command << "-u #{@options[:user]}" if @options[:user]
63
-
63
+
64
64
  command_results = %x[#{command.join(' ')} 2> /dev/null]
65
65
  @current_crontab = $?.exitstatus.zero? ? prepare(command_results) : ''
66
66
  end
67
-
67
+
68
68
  def write_crontab(contents)
69
69
  tmp_cron_file = Tempfile.open('whenever_tmp_cron')
70
70
  tmp_cron_file << contents
@@ -86,8 +86,8 @@ module Whenever
86
86
  exit(1)
87
87
  end
88
88
  end
89
-
90
- def updated_crontab
89
+
90
+ def updated_crontab
91
91
  # Check for unopened or unclosed identifier blocks
92
92
  if read_crontab =~ Regexp.new("^#{comment_open}\s*$") && (read_crontab =~ Regexp.new("^#{comment_close}\s*$")).nil?
93
93
  warn "[fail] Unclosed indentifier; Your crontab file contains '#{comment_open}', but no '#{comment_close}'"
@@ -96,7 +96,7 @@ module Whenever
96
96
  warn "[fail] Unopened indentifier; Your crontab file contains '#{comment_close}', but no '#{comment_open}'"
97
97
  exit(1)
98
98
  end
99
-
99
+
100
100
  # If an existing identier block is found, replace it with the new cron entries
101
101
  if read_crontab =~ Regexp.new("^#{comment_open}\s*$") && read_crontab =~ Regexp.new("^#{comment_close}\s*$")
102
102
  # If the existing crontab file contains backslashes they get lost going through gsub.
@@ -106,7 +106,7 @@ module Whenever
106
106
  [read_crontab, whenever_cron].join("\n\n")
107
107
  end.gsub(/\n{3,}/, "\n\n") # More than two newlines becomes just two.
108
108
  end
109
-
109
+
110
110
  def prepare(contents)
111
111
  # Strip n lines from the top of the file as specified by the :cut option.
112
112
  # Use split with a -1 limit option to ensure the join is able to rebuild
@@ -114,19 +114,19 @@ module Whenever
114
114
  stripped_contents = contents.split($/,-1)[@options[:cut]..-1].join($/)
115
115
 
116
116
  # Some cron implementations require all non-comment lines to be newline-
117
- # terminated. (issue #95) Strip all newlines and replace with the default
117
+ # terminated. (issue #95) Strip all newlines and replace with the default
118
118
  # platform record seperator ($/)
119
119
  stripped_contents.gsub!(/\s+$/, $/)
120
120
  end
121
-
121
+
122
122
  def comment_base
123
123
  "Whenever generated tasks for: #{@options[:identifier]}"
124
124
  end
125
-
125
+
126
126
  def comment_open
127
127
  "# Begin #{comment_base}"
128
128
  end
129
-
129
+
130
130
  def comment_close
131
131
  "# End #{comment_base}"
132
132
  end
@@ -20,9 +20,16 @@ else
20
20
  job_type :script, "cd :path && :environment_variable=:environment script/:task :output"
21
21
  end
22
22
 
23
- # Create a runner job that's appropriate for the Rails version,
24
- if Whenever.rails3?
25
- job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
26
- else
27
- job_type :runner, "cd :path && script/runner -e :environment ':task' :output"
23
+ # Create a runner job that's appropriate for the Rails version
24
+ def runner_for_app
25
+ case
26
+ when Whenever.bin_rails?
27
+ "bin/rails runner"
28
+ when Whenever.script_rails?
29
+ "script/rails runner"
30
+ else
31
+ "script/runner"
32
+ end
28
33
  end
34
+
35
+ job_type :runner, "cd :path && #{runner_for_app} -e :environment ':task' :output"
@@ -1,3 +1,3 @@
1
1
  module Whenever
2
- VERSION = '0.8.3'
2
+ VERSION = '0.8.4'
3
3
  end
@@ -161,6 +161,18 @@ NEW_CRON
161
161
  end
162
162
  end
163
163
 
164
+ context "A command line clear with no schedule file" do
165
+ setup do
166
+ File.expects(:exists?).with('config/schedule.rb').returns(false)
167
+ @command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
168
+ end
169
+
170
+ should "run successfully" do
171
+ @command.expects(:write_crontab).returns(true)
172
+ assert @command.run
173
+ end
174
+ end
175
+
164
176
  context "A command line update with no identifier" do
165
177
  setup do
166
178
  File.expects(:exists?).with('config/schedule.rb').returns(true)
@@ -107,10 +107,10 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
107
107
  end
108
108
  end
109
109
 
110
- context "A runner for a Rails 3 app" do
110
+ context "A runner for an app with bin/rails" do
111
111
  setup do
112
112
  Whenever.expects(:path).at_least_once.returns('/my/path')
113
- Whenever.expects(:rails3?).returns(true)
113
+ Whenever.expects(:bin_rails?).returns(true)
114
114
  @output = Whenever.cron \
115
115
  <<-file
116
116
  set :job_template, nil
@@ -120,7 +120,25 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
120
120
  file
121
121
  end
122
122
 
123
- should "use the Rails 3 runner job by default" do
123
+ should "use a script/rails runner job by default" do
124
+ assert_match two_hours + %( cd /my/path && bin/rails runner -e production 'blahblah'), @output
125
+ end
126
+ end
127
+
128
+ context "A runner for an app with script/rails" do
129
+ setup do
130
+ Whenever.expects(:path).at_least_once.returns('/my/path')
131
+ Whenever.expects(:script_rails?).returns(true)
132
+ @output = Whenever.cron \
133
+ <<-file
134
+ set :job_template, nil
135
+ every 2.hours do
136
+ runner 'blahblah'
137
+ end
138
+ file
139
+ end
140
+
141
+ should "use a script/rails runner job by default" do
124
142
  assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), @output
125
143
  end
126
144
  end
@@ -288,4 +306,4 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
288
306
  end
289
307
  end
290
308
 
291
- end
309
+ end
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Javan Makhmali"]
10
10
  s.email = ["javan@javan.us"]
11
+ s.license = "MIT"
11
12
  s.homepage = ""
12
13
  s.summary = %q{Cron jobs in ruby.}
13
14
  s.description = %q{Clean ruby syntax for writing and deploying cron jobs.}
@@ -17,9 +18,14 @@ Gem::Specification.new do |s|
17
18
  s.require_paths = ["lib"]
18
19
 
19
20
  s.add_dependency "chronic", ">= 0.6.3"
20
- s.add_dependency "activesupport", ">= 2.3.4"
21
21
 
22
- s.add_development_dependency "shoulda-matchers", "2.0.0"
22
+ if RUBY_VERSION < "1.9"
23
+ s.add_dependency "activesupport", ">= 2.3.4", "< 4.0"
24
+ else
25
+ s.add_dependency "activesupport", ">= 2.3.4"
26
+ end
27
+
28
+ s.add_development_dependency "shoulda-matchers", "<= 2.0.0" if RUBY_VERSION < "1.9"
23
29
  s.add_development_dependency "shoulda", ">= 2.1.1"
24
30
  s.add_development_dependency "mocha", ">= 0.9.5"
25
31
  s.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whenever
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2013-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.3.4
41
- - !ruby/object:Gem::Dependency
42
- name: shoulda-matchers
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 2.0.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 2.0.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: shoulda
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +122,8 @@ files:
136
122
  - test/unit/job_test.rb
137
123
  - whenever.gemspec
138
124
  homepage: ''
139
- licenses: []
125
+ licenses:
126
+ - MIT
140
127
  metadata: {}
141
128
  post_install_message:
142
129
  rdoc_options: []