whenever 0.8.4 → 0.9.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c96bb55bfcc94c54bab65174a8fb046aa4bfcff1
4
- data.tar.gz: fbce8b6cd1f6c8558e9281af9f6cbccade7dcd71
3
+ metadata.gz: 9b7b1f246b22c910d7f50418153572714548f3a7
4
+ data.tar.gz: cc253c6228c7e36d7f07032d5272e442d2eb6b08
5
5
  SHA512:
6
- metadata.gz: a23ed3067c55356fb7f98f18d267d508d410cbe63a9ea2dc1f3aaa491bfa6df03cf856ff315a2adb64290cab7fa9348ed486ac362afec8b35583d4efc251eef6
7
- data.tar.gz: 3e79b8eba708dd80fa79fa8ba80a81205a889f196f6a5a00ee3cdfce82c669ef93e96a10c321cfb4c7cd7fe9addc1ca75860aaa5c082da6ed6400def6c42d575
6
+ metadata.gz: bccd024f09f270d95b331f2c7177dad4914865eaacb5f83392f12a30fd1272cdfb3179dfaa731d84d63796a1f12a00d38b612b220fd46373a06ed7d0eeb0c90b
7
+ data.tar.gz: 8cfcfb3ae75cf378878631528a397618f369743639e34e51a63a53b6ee0c59c919969cbb7152e59775a46478fb0b3232ec228a69c1b968668cb77a360a734106
data/.travis.yml CHANGED
@@ -1,8 +1,10 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 1.8.7
3
4
  - 1.9.2
4
5
  - 1.9.3
5
6
  - 2.0.0
7
+ - 2.1.0
6
8
  - ree
7
9
  - jruby
8
10
  - jruby-18mode
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
- ### 0.9.0 (unreleased)
1
+ ### 0.9.2 / March 4, 2014
2
2
 
3
- * Time zone support
3
+ * Fix issues generating arguments for `execute` in Capistrano 3 tasks. [Javan Makhmali]
4
+
5
+
6
+ ### 0.9.1 / March 2, 2014
7
+
8
+ * Pass `--roles` option to `whenever` in Capistrano 3 tasks. [betesh, Javan Makhmali]
9
+
10
+ * Allow setting `:whenever_command` for Capistrano 3. [Javan Makhmali]
11
+
12
+ * Allow `:whenever` command to be mapped in SSHKit. [Javan Makhmali]
13
+
14
+
15
+ ### 0.9.0 / December 17, 2013
16
+
17
+ * Capistrano V3 support. [Philip Hallstrom]
18
+
19
+ * Process params in job templates. [Austin Ziegler]
4
20
 
5
21
 
6
22
  ### 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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Javan Makhmali
1
+ Copyright (c) 2014 Javan Makhmali
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
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
 
@@ -106,7 +106,7 @@ In your "config/deploy.rb" file:
106
106
  require "whenever/capistrano"
107
107
  ```
108
108
 
109
- Take a look at the recipe for options you can set. <http://github.com/javan/whenever/blob/master/lib/whenever/capistrano/recipes.rb>
109
+ Take a look at the recipe for options you can set. <https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v2/recipes.rb>
110
110
  For example, if you're using bundler do this:
111
111
 
112
112
  ```ruby
@@ -131,6 +131,20 @@ 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
+ 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.
143
+
144
+ ```ruby
145
+ set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }
146
+ ```
147
+
134
148
  ### Capistrano roles
135
149
 
136
150
  The first thing to know about the new roles support is that it is entirely
@@ -193,7 +207,7 @@ If your production environment uses RVM (Ruby Version Manager) you will run into
193
207
 
194
208
  `rvm_trust_rvmrcs_flag=1`
195
209
 
196
- This tells rvm to trust all rvmrc files, which is documented here: http://wayneeseguin.beginrescueend.com/2010/08/22/ruby-environment-version-manager-rvm-1-0-0/
210
+ This tells rvm to trust all rvmrc files.
197
211
 
198
212
  ### The `whenever` command
199
213
 
@@ -221,8 +235,8 @@ It's a little bit dated now, but remains a good introduction.
221
235
 
222
236
  ----
223
237
 
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)
238
+ Compatible with Ruby 1.8.7-2.1.0, JRuby, and Rubinius. [![Build Status](https://secure.travis-ci.org/javan/whenever.png)](http://travis-ci.org/javan/whenever)
225
239
 
226
240
  ----
227
241
 
228
- Copyright &copy; 2013 Javan Makhmali
242
+ Copyright &copy; 2014 Javan Makhmali
@@ -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,43 @@
1
+ namespace :whenever do
2
+ def setup_whenever_task(*args, &block)
3
+ args = Array(fetch(:whenever_command)) + args
4
+
5
+ on roles fetch(:whenever_roles) do |host|
6
+ host_args = Array(yield(host))
7
+ within release_path do
8
+ with fetch(:whenever_command_environment_variables) do
9
+ execute *(args + host_args)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ desc "Update application's crontab entries using Whenever"
16
+ task :update_crontab do
17
+ setup_whenever_task do |host|
18
+ roles = host.roles_array.join(",")
19
+ [fetch(:whenever_update_flags), "--roles=#{roles}"]
20
+ end
21
+ end
22
+
23
+ desc "Clear application's crontab entries using Whenever"
24
+ task :clear_crontab do
25
+ setup_whenever_task(fetch(:whenever_clear_flags))
26
+ end
27
+
28
+ after "deploy:updated", "whenever:update_crontab"
29
+ after "deploy:reverted", "whenever:update_crontab"
30
+ end
31
+
32
+ namespace :load do
33
+ task :defaults do
34
+ set :whenever_roles, ->{ :db }
35
+ set :whenever_command, ->{ [:bundle, :exec, :whenever] }
36
+ set :whenever_command_environment_variables, ->{ {} }
37
+ set :whenever_identifier, ->{ fetch :application }
38
+ set :whenever_environment, ->{ fetch :rails_env, "production" }
39
+ set :whenever_variables, ->{ "environment=#{fetch :whenever_environment}" }
40
+ set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
41
+ set :whenever_clear_flags, ->{ "--clear-crontab #{fetch :whenever_identifier}" }
42
+ end
43
+ end
@@ -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
data/lib/whenever/job.rb CHANGED
@@ -17,11 +17,8 @@ module Whenever
17
17
  end
18
18
 
19
19
  def output
20
- job = process_template(@template, @options).strip
21
- out = process_template(@job_template, { :job => job }).strip
22
- if out =~ /\n/
23
- raise ArgumentError, "Task contains newline"
24
- end
20
+ job = process_template(@template, @options)
21
+ out = process_template(@job_template, @options.merge(:job => job))
25
22
  out.gsub(/%/, '\%')
26
23
  end
27
24
 
@@ -43,7 +40,7 @@ module Whenever
43
40
  else
44
41
  option
45
42
  end
46
- end
43
+ end.squish
47
44
  end
48
45
 
49
46
  def escape_single_quotes(str)
@@ -9,20 +9,7 @@ set :path, Whenever.path
9
9
  # http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
10
10
  set :job_template, "/bin/bash -l -c ':job'"
11
11
 
12
- job_type :command, ":task :output"
13
-
14
- # Run rake through bundler if possible
15
- if Whenever.bundler?
16
- job_type :rake, "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
17
- job_type :script, "cd :path && :environment_variable=:environment bundle exec script/:task :output"
18
- else
19
- job_type :rake, "cd :path && :environment_variable=:environment rake :task --silent :output"
20
- job_type :script, "cd :path && :environment_variable=:environment script/:task :output"
21
- end
22
-
23
- # Create a runner job that's appropriate for the Rails version
24
- def runner_for_app
25
- case
12
+ set :runner_command, case
26
13
  when Whenever.bin_rails?
27
14
  "bin/rails runner"
28
15
  when Whenever.script_rails?
@@ -30,6 +17,10 @@ def runner_for_app
30
17
  else
31
18
  "script/runner"
32
19
  end
33
- end
34
20
 
35
- job_type :runner, "cd :path && #{runner_for_app} -e :environment ':task' :output"
21
+ set :bundle_command, Whenever.bundler? ? "bundle exec" : ""
22
+
23
+ job_type :command, ":task :output"
24
+ job_type :rake, "cd :path && :environment_variable=:environment :bundle_command rake :task --silent :output"
25
+ job_type :script, "cd :path && :environment_variable=:environment :bundle_command script/:task :output"
26
+ job_type :runner, "cd :path && :runner_command -e :environment ':task' :output"
@@ -0,0 +1,43 @@
1
+ namespace :whenever do
2
+ def setup_whenever_task(*args, &block)
3
+ args = Array(fetch(:whenever_command)) + args
4
+
5
+ on roles fetch(:whenever_roles) do |host|
6
+ host_args = Array(yield(host))
7
+ within release_path do
8
+ with fetch(:whenever_command_environment_variables) do
9
+ execute *(args + host_args)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ desc "Update application's crontab entries using Whenever"
16
+ task :update_crontab do
17
+ setup_whenever_task do |host|
18
+ roles = host.roles_array.join(",")
19
+ [fetch(:whenever_update_flags), "--roles=#{roles}"]
20
+ end
21
+ end
22
+
23
+ desc "Clear application's crontab entries using Whenever"
24
+ task :clear_crontab do
25
+ setup_whenever_task(fetch(:whenever_clear_flags))
26
+ end
27
+
28
+ after "deploy:updated", "whenever:update_crontab"
29
+ after "deploy:reverted", "whenever:update_crontab"
30
+ end
31
+
32
+ namespace :load do
33
+ task :defaults do
34
+ set :whenever_roles, ->{ :db }
35
+ set :whenever_command, ->{ [:bundle, :exec, :whenever] }
36
+ set :whenever_command_environment_variables, ->{ {} }
37
+ set :whenever_identifier, ->{ fetch :application }
38
+ set :whenever_environment, ->{ fetch :rails_env, "production" }
39
+ set :whenever_variables, ->{ "environment=#{fetch :whenever_environment}" }
40
+ set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
41
+ set :whenever_clear_flags, ->{ "--clear-crontab #{fetch :whenever_identifier}" }
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Whenever
2
- VERSION = '0.8.4'
2
+ VERSION = '0.9.2'
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
@@ -54,14 +54,13 @@ class JobTest < Test::Unit::TestCase
54
54
  assert_equal %q(before percent preceded by a backslash -> \\\% <- after), job.output
55
55
  end
56
56
 
57
- should "reject newlines" do
57
+ should "squish spaces and newlines" do
58
58
  job = new_job(
59
59
  :template => "before :foo after",
60
- :foo => "newline -> \n <- newline"
60
+ :foo => "newline -> \n <- newline space -> <- space"
61
61
  )
62
- assert_raise ArgumentError do
63
- job.output
64
- end
62
+
63
+ assert_equal "before newline -> <- newline space -> <- space after", job.output
65
64
  end
66
65
  end
67
66
 
@@ -100,6 +99,11 @@ class JobTest < Test::Unit::TestCase
100
99
  assert_equal 'left abc123 right', job.output
101
100
  end
102
101
 
102
+ should "reuse parameter in the job template" do
103
+ job = new_job(:template => ':path :task', :path => 'path', :task => "abc123", :job_template => ':path left :job right')
104
+ assert_equal 'path left path abc123 right', job.output
105
+ end
106
+
103
107
  should "escape single quotes" do
104
108
  job = new_job(:template => "before ':task' after", :task => "quote -> ' <- quote", :job_template => "left ':job' right")
105
109
  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.2
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: 2014-03-04 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.0.14
145
148
  signing_key:
146
149
  specification_version: 4
147
150
  summary: Cron jobs in ruby.