whenever 0.8.4 → 0.9.0

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: c96bb55bfcc94c54bab65174a8fb046aa4bfcff1
4
- data.tar.gz: fbce8b6cd1f6c8558e9281af9f6cbccade7dcd71
3
+ metadata.gz: 57fab9163bf16e91c0bd53c2a07a42ff6d27808c
4
+ data.tar.gz: a2391734b582cffc7ca2d1b03a4dd8302c84f7ca
5
5
  SHA512:
6
- metadata.gz: a23ed3067c55356fb7f98f18d267d508d410cbe63a9ea2dc1f3aaa491bfa6df03cf856ff315a2adb64290cab7fa9348ed486ac362afec8b35583d4efc251eef6
7
- data.tar.gz: 3e79b8eba708dd80fa79fa8ba80a81205a889f196f6a5a00ee3cdfce82c669ef93e96a10c321cfb4c7cd7fe9addc1ca75860aaa5c082da6ed6400def6c42d575
6
+ metadata.gz: 923b43401e3f57f83c1a6095a58c127157bf884433939cf64c8deb766cb48873526c91faf009774358b965b9c3768a159fbb9cafde83ed3d68c1a38f68cae954
7
+ data.tar.gz: 185ac668deaa57c7cfdd4b192b8d19b0bf5bc70e68fe5d5b54454ef6ecd6b30dba0889af0da219095bb4f50327158bf8be0342d17737adb60e9613c5ac5b0bb4
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 1.8.7
3
4
  - 1.9.2
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
- ### 0.9.0 (unreleased)
1
+ ### 0.9.0 / December 17, 2013
2
2
 
3
- * Time zone support
3
+ * Capistrano V3 support. [Philip Hallstrom]
4
+
5
+ * Process params in job templates. [Austin Ziegler]
4
6
 
5
7
 
6
8
  ### 0.8.4 / July 22, 2012
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in newever.gemspec
4
- gemspec
3
+ # Specify your gem's dependencies in whenever.gemspec
4
+ gemspec
5
+
6
+ if RUBY_VERSION < "1.9.3"
7
+ gem "activesupport", "< 4.0.0"
8
+ gem "shoulda-matchers", "<= 2.0.0"
9
+ end
data/README.md CHANGED
@@ -98,7 +98,7 @@ set :job_template, nil
98
98
 
99
99
  ### Capistrano integration
100
100
 
101
- Use the built-in Capistrano recipe for easy crontab updates with deploys.
101
+ Use the built-in Capistrano recipe for easy crontab updates with deploys. For Capistrano V3, see the next section.
102
102
 
103
103
  In your "config/deploy.rb" file:
104
104
 
@@ -131,6 +131,28 @@ set :whenever_identifier, defer { "#{application}_#{stage}" }
131
131
  require "whenever/capistrano"
132
132
  ```
133
133
 
134
+ ### Capistrano V3 Integration
135
+
136
+ In your "Capfile" file:
137
+
138
+ ```ruby
139
+ require "whenever/capistrano"
140
+ ```
141
+
142
+ If you're using bundler do this. **DO NOT** set ':whenever_command' to 'bundle exec whenever'. It will **NOT** work.
143
+ Be default, 'bundle exec whenever' will be called. If you need something different and the command contains a space
144
+ you will need to map it via the following method. This is an issue with SSHKit.
145
+
146
+ ```ruby
147
+ SSHKit.config.command_map[:whenever] = "bundle exec whenever"
148
+ ```
149
+
150
+ Take a look at the load:defaults (bottom of file) task for options you can set. <http://github.com/javan/whenever/blob/master/lib/whenever/tasks/whenever.rake>. For example, to namespace the crontab entries by application and stage do this.
151
+
152
+ ```ruby
153
+ set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }
154
+ ```
155
+
134
156
  ### Capistrano roles
135
157
 
136
158
  The first thing to know about the new roles support is that it is entirely
@@ -221,7 +243,7 @@ It's a little bit dated now, but remains a good introduction.
221
243
 
222
244
  ----
223
245
 
224
- Compatible with Ruby 1.8.7-1.9.3, JRuby, and Rubinius. [![Build Status](https://secure.travis-ci.org/javan/whenever.png)](http://travis-ci.org/javan/whenever)
246
+ Compatible with Ruby 1.8.7-2.0.0, JRuby, and Rubinius. [![Build Status](https://secure.travis-ci.org/javan/whenever.png)](http://travis-ci.org/javan/whenever)
225
247
 
226
248
  ----
227
249
 
@@ -1,8 +1,7 @@
1
- require "whenever/capistrano/recipes"
1
+ require 'capistrano/version'
2
2
 
3
- Capistrano::Configuration.instance(:must_exist).load do
4
- # Write the new cron jobs near the end.
5
- before "deploy:finalize_update", "whenever:update_crontab"
6
- # If anything goes wrong, undo.
7
- after "deploy:rollback", "whenever:update_crontab"
3
+ if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')
4
+ load File.expand_path("../tasks/whenever.rake", __FILE__)
5
+ else
6
+ require 'whenever/capistrano/v2/hooks'
8
7
  end
@@ -0,0 +1,8 @@
1
+ require "whenever/capistrano/v2/recipes"
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ # Write the new cron jobs near the end.
5
+ before "deploy:finalize_update", "whenever:update_crontab"
6
+ # If anything goes wrong, undo.
7
+ after "deploy:rollback", "whenever:update_crontab"
8
+ end
@@ -1,4 +1,4 @@
1
- require 'whenever/capistrano/support'
1
+ require 'whenever/capistrano/v2/support'
2
2
 
3
3
  Capistrano::Configuration.instance(:must_exist).load do
4
4
  Whenever::CapistranoSupport.load_into(self)
@@ -0,0 +1,44 @@
1
+ namespace :whenever do
2
+ desc "Update application's crontab entries using Whenever"
3
+ task :update_crontab do
4
+ on roles fetch(:whenever_roles) do
5
+ within release_path do
6
+ if fetch(:whenever_command)
7
+ execute fetch(:whenever_command), fetch(:whenever_update_flags)
8
+ else
9
+ execute :bundle, :exec, :whenever, fetch(:whenever_update_flags)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ desc "Clear application's crontab entries using Whenever"
16
+ task :clear_crontab do
17
+ on roles fetch(:whenever_roles) do
18
+ within release_path do
19
+ if fetch(:whenever_command)
20
+ execute %{#{fetch(:whenever_command)} #{fetch(:whenever_clear_flags)}}
21
+ else
22
+ execute :bundle, :exec, :whenever, fetch(:whenever_clear_flags)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ after 'deploy:updated', 'whenever:update_crontab'
29
+ after 'deploy:reverted', 'whenever:update_crontab'
30
+
31
+ end
32
+
33
+ namespace :load do
34
+ task :defaults do
35
+ set :whenever_roles, ->{ :db }
36
+ set :whenever_options, ->{ {:roles => fetch(:whenever_roles)} }
37
+ set :whenever_command, ->{ }
38
+ set :whenever_identifier, ->{ fetch :application }
39
+ set :whenever_environment, ->{ fetch :rails_env, "production" }
40
+ set :whenever_variables, ->{ "environment=#{fetch :whenever_environment}" }
41
+ set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
42
+ set :whenever_clear_flags, ->{ "--clear-crontab #{fetch :whenever_identifier}" }
43
+ end
44
+ end
data/lib/whenever/job.rb CHANGED
@@ -18,7 +18,7 @@ module Whenever
18
18
 
19
19
  def output
20
20
  job = process_template(@template, @options).strip
21
- out = process_template(@job_template, { :job => job }).strip
21
+ out = process_template(@job_template, @options.merge(:job => job)).strip
22
22
  if out =~ /\n/
23
23
  raise ArgumentError, "Task contains newline"
24
24
  end
@@ -0,0 +1,44 @@
1
+ namespace :whenever do
2
+ desc "Update application's crontab entries using Whenever"
3
+ task :update_crontab do
4
+ on roles fetch(:whenever_roles) do
5
+ within release_path do
6
+ if fetch(:whenever_command)
7
+ execute fetch(:whenever_command), fetch(:whenever_update_flags)
8
+ else
9
+ execute :bundle, :exec, :whenever, fetch(:whenever_update_flags)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ desc "Clear application's crontab entries using Whenever"
16
+ task :clear_crontab do
17
+ on roles fetch(:whenever_roles) do
18
+ within release_path do
19
+ if fetch(:whenever_command)
20
+ execute %{#{fetch(:whenever_command)} #{fetch(:whenever_clear_flags)}}
21
+ else
22
+ execute :bundle, :exec, :whenever, fetch(:whenever_clear_flags)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ after 'deploy:updated', 'whenever:update_crontab'
29
+ after 'deploy:reverted', 'whenever:update_crontab'
30
+
31
+ end
32
+
33
+ namespace :load do
34
+ task :defaults do
35
+ set :whenever_roles, ->{ :db }
36
+ set :whenever_options, ->{ {:roles => fetch(:whenever_roles)} }
37
+ set :whenever_command, ->{ }
38
+ set :whenever_identifier, ->{ fetch :application }
39
+ set :whenever_environment, ->{ fetch :rails_env, "production" }
40
+ set :whenever_variables, ->{ "environment=#{fetch :whenever_environment}" }
41
+ set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
42
+ set :whenever_clear_flags, ->{ "--clear-crontab #{fetch :whenever_identifier}" }
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Whenever
2
- VERSION = '0.8.4'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -35,6 +35,24 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
35
35
  end
36
36
  end
37
37
 
38
+ context "A plain command with a job_template using a normal parameter" do
39
+ setup do
40
+ @output = Whenever.cron \
41
+ <<-file
42
+ set :job_template, "/bin/bash -l -c 'cd :path && :job'"
43
+ every 2.hours do
44
+ set :path, "/tmp"
45
+ command "blahblah"
46
+ end
47
+ file
48
+ end
49
+
50
+ should "output the command using that job_template" do
51
+ assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'cd \/tmp \&\& blahblah'$/, @output
52
+ end
53
+ end
54
+
55
+
38
56
  context "A plain command that overrides the job_template set" do
39
57
  setup do
40
58
  @output = Whenever.cron \
@@ -52,6 +70,24 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
52
70
  end
53
71
  end
54
72
 
73
+ context "A plain command that overrides the job_template set using a parameter" do
74
+ setup do
75
+ @output = Whenever.cron \
76
+ <<-file
77
+ set :job_template, "/bin/bash -l -c 'cd :path && :job'"
78
+ every 2.hours do
79
+ set :path, "/tmp"
80
+ command "blahblah", :job_template => "/bin/sh -l -c 'cd :path && :job'"
81
+ end
82
+ file
83
+ end
84
+
85
+ should "output the command using that job_template" do
86
+ assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'cd \/tmp && blahblah'$/, @output
87
+ assert_no_match /bash/, @output
88
+ end
89
+ end
90
+
55
91
  context "A plain command that is conditional on default environent and path" do
56
92
  setup do
57
93
  Whenever.expects(:path).at_least_once.returns('/what/you/want')
@@ -1,5 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require File.expand_path(File.dirname(__FILE__) + "/../../lib/whenever/capistrano/support")
2
+ require File.expand_path(File.dirname(__FILE__) + "/../../lib/whenever/capistrano/v2/support")
3
3
 
4
4
  class CapistranoSupportTestSubject
5
5
  include Whenever::CapistranoSupport
@@ -100,6 +100,11 @@ class JobTest < Test::Unit::TestCase
100
100
  assert_equal 'left abc123 right', job.output
101
101
  end
102
102
 
103
+ should "reuse parameter in the job template" do
104
+ job = new_job(:template => ':path :task', :path => 'path', :task => "abc123", :job_template => ':path left :job right')
105
+ assert_equal 'path left path abc123 right', job.output
106
+ end
107
+
103
108
  should "escape single quotes" do
104
109
  job = new_job(:template => "before ':task' after", :task => "quote -> ' <- quote", :job_template => "left ':job' right")
105
110
  assert_equal %q(left 'before '\''quote -> '\\''\\'\\'''\\'' <- quote'\'' after' right), job.output
data/whenever.gemspec CHANGED
@@ -18,14 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_dependency "chronic", ">= 0.6.3"
21
+ s.add_dependency "activesupport", ">= 2.3.4"
21
22
 
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"
29
23
  s.add_development_dependency "shoulda", ">= 2.1.1"
30
24
  s.add_development_dependency "mocha", ">= 0.9.5"
31
25
  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.4
4
+ version: 0.9.0
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-23 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
@@ -100,14 +100,17 @@ files:
100
100
  - bin/wheneverize
101
101
  - lib/whenever.rb
102
102
  - lib/whenever/capistrano.rb
103
- - lib/whenever/capistrano/recipes.rb
104
- - lib/whenever/capistrano/support.rb
103
+ - lib/whenever/capistrano/v2/hooks.rb
104
+ - lib/whenever/capistrano/v2/recipes.rb
105
+ - lib/whenever/capistrano/v2/support.rb
106
+ - lib/whenever/capistrano/v3/tasks/whenever.rake
105
107
  - lib/whenever/command_line.rb
106
108
  - lib/whenever/cron.rb
107
109
  - lib/whenever/job.rb
108
110
  - lib/whenever/job_list.rb
109
111
  - lib/whenever/output_redirection.rb
110
112
  - lib/whenever/setup.rb
113
+ - lib/whenever/tasks/whenever.rake
111
114
  - lib/whenever/version.rb
112
115
  - test/functional/command_line_test.rb
113
116
  - test/functional/output_at_test.rb
@@ -141,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
144
  version: '0'
142
145
  requirements: []
143
146
  rubyforge_project:
144
- rubygems_version: 2.0.2
147
+ rubygems_version: 2.1.11
145
148
  signing_key:
146
149
  specification_version: 4
147
150
  summary: Cron jobs in ruby.