moneypools-whenever 0.1.0 → 0.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.
@@ -0,0 +1,16 @@
1
+ module Whenever
2
+ class JobSequence < Array
3
+ attr_writer :dependent
4
+
5
+ def initialize(options={}, size=0, obj=nil)
6
+ super(size, obj)
7
+
8
+ @dependent = options.fetch(:dependent, true)
9
+ end
10
+
11
+ def to_single_job
12
+ concatenation = @dependent ? " && " : "; "
13
+ Job::Default.new(:task => map(&:output).join(concatenation))
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,85 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{moneypools-whenever}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Javan Makhmali"]
12
+ s.date = %q{2009-11-16}
13
+ s.description = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
14
+ s.email = %q{javan@javan.us}
15
+ s.executables = ["whenever", "wheneverize"]
16
+ s.extra_rdoc_files = [
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "CHANGELOG.rdoc",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/whenever",
26
+ "bin/wheneverize",
27
+ "lib/whenever.rb",
28
+ "lib/whenever/base.rb",
29
+ "lib/whenever/command_line.rb",
30
+ "lib/whenever/job_list.rb",
31
+ "lib/whenever/job_sequence.rb",
32
+ "lib/whenever/job_types/cap_task.rb",
33
+ "lib/whenever/job_types/default.rb",
34
+ "lib/whenever/job_types/rake_task.rb",
35
+ "lib/whenever/job_types/runner.rb",
36
+ "lib/whenever/outputs/cron.rb",
37
+ "lib/whenever/outputs/cron/output_redirection.rb",
38
+ "lib/whenever/version.rb",
39
+ "moneypools-whenever.gemspec",
40
+ "test/command_line_test.rb",
41
+ "test/cron_test.rb",
42
+ "test/in_sequence_test.rb",
43
+ "test/job_sequence_test.rb",
44
+ "test/output_at_test.rb",
45
+ "test/output_cap_test.rb",
46
+ "test/output_command_test.rb",
47
+ "test/output_env_test.rb",
48
+ "test/output_rake_test.rb",
49
+ "test/output_redirection_test.rb",
50
+ "test/output_runner_test.rb",
51
+ "test/test_helper.rb"
52
+ ]
53
+ s.homepage = %q{http://github.com/javan/whenever}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.5}
57
+ s.summary = %q{Clean ruby syntax for defining and deploying messy cron jobs.}
58
+ s.test_files = [
59
+ "test/command_line_test.rb",
60
+ "test/cron_test.rb",
61
+ "test/in_sequence_test.rb",
62
+ "test/job_sequence_test.rb",
63
+ "test/output_at_test.rb",
64
+ "test/output_cap_test.rb",
65
+ "test/output_command_test.rb",
66
+ "test/output_env_test.rb",
67
+ "test/output_rake_test.rb",
68
+ "test/output_redirection_test.rb",
69
+ "test/output_runner_test.rb",
70
+ "test/test_helper.rb"
71
+ ]
72
+
73
+ if s.respond_to? :specification_version then
74
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
+ s.add_runtime_dependency(%q<chronic>, [">= 0.2.3"])
79
+ else
80
+ s.add_dependency(%q<chronic>, [">= 0.2.3"])
81
+ end
82
+ else
83
+ s.add_dependency(%q<chronic>, [">= 0.2.3"])
84
+ end
85
+ end
@@ -0,0 +1,94 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class InSequenceTest < Test::Unit::TestCase
4
+ context "A pair of tasks in the same time block that should be executed in a dependent sequence" do
5
+ setup do
6
+ @output = Whenever.cron \
7
+ <<-file
8
+ set :path, '/my/path'
9
+ every 2.hours do
10
+ in_sequence do
11
+ cap "first_task"
12
+ rake "second_task"
13
+ end
14
+ end
15
+ file
16
+ end
17
+
18
+ should "output the pair of tasks using &&" do
19
+ assert_match 'cd /my/path && RAILS_ENV=production /usr/bin/env cap first_task && cd /my/path && RAILS_ENV=production /usr/bin/env rake second_task', @output
20
+ end
21
+ end
22
+
23
+ context "A pair of tasks in the same time block that should be executed in a independent sequence" do
24
+ setup do
25
+ @output = Whenever.cron \
26
+ <<-file
27
+ set :path, '/my/path'
28
+ every 2.hours do
29
+ in_sequence(:dependent => false) do
30
+ cap "first_task"
31
+ rake "second_task"
32
+ end
33
+ end
34
+ file
35
+ end
36
+
37
+ should "output the pair of tasks using ;" do
38
+ assert_match 'cd /my/path && RAILS_ENV=production /usr/bin/env cap first_task; cd /my/path && RAILS_ENV=production /usr/bin/env rake second_task', @output
39
+ end
40
+ end
41
+
42
+ context "A set of tasks in the same time block that should be grouped and by their sequence" do
43
+ setup do
44
+ @output = Whenever.cron \
45
+ <<-file
46
+ set :path, '/my/path'
47
+ every 2.hours do
48
+ in_sequence do
49
+ cap "first_task"
50
+ rake "second_task"
51
+ end
52
+
53
+ in_sequence do
54
+ runner "third_task"
55
+ command "fourth_task"
56
+ end
57
+ end
58
+ file
59
+ end
60
+
61
+ should "output each sequence as its own sequential task" do
62
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production /usr/bin/env cap first_task && cd /my/path && RAILS_ENV=production /usr/bin/env rake second_task', @output
63
+ assert_match two_hours + ' /my/path/script/runner -e production "third_task" && fourth_task', @output
64
+ end
65
+ end
66
+
67
+
68
+ context "A set of tasks in different time blocks that should each be grouped and by their sequence and time" do
69
+ setup do
70
+ @output = Whenever.cron \
71
+ <<-file
72
+ set :path, '/my/path'
73
+ every 1.hour do
74
+ in_sequence do
75
+ cap "first_task"
76
+ rake "second_task"
77
+ end
78
+ end
79
+
80
+ every 2.hours do
81
+ in_sequence do
82
+ runner "third_task"
83
+ command "fourth_task"
84
+ end
85
+ end
86
+ file
87
+ end
88
+
89
+ should "output each sequence as its own sequential task at the correct time" do
90
+ assert_match '0 * * * * cd /my/path && RAILS_ENV=production /usr/bin/env cap first_task && cd /my/path && RAILS_ENV=production /usr/bin/env rake second_task', @output
91
+ assert_match two_hours + ' /my/path/script/runner -e production "third_task" && fourth_task', @output
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class JobSequenceTest < Test::Unit::TestCase
4
+ context "creating sequential jobs" do
5
+ setup do
6
+ @path = "/my/path"
7
+ end
8
+
9
+ should "produce a single job with task unchanged" do
10
+ sequence = Whenever::JobSequence.new
11
+ sequence << Whenever::Job::Default.new(:task => "my_task", :path => @path)
12
+ assert_equal sequence.to_single_job.output, "my_task"
13
+ end
14
+
15
+ context "with dependent sequences" do
16
+ should "concatenate multiple jobs with && operator" do
17
+ sequence = Whenever::JobSequence.new
18
+ sequence << Whenever::Job::Default.new(:task => "first_task", :path => @path)
19
+ sequence << Whenever::Job::Default.new(:task => "second_task", :path => @path)
20
+
21
+ assert_equal sequence.to_single_job.output, "first_task && second_task"
22
+ end
23
+ end
24
+
25
+ context "with independent sequences" do
26
+ should "concatenate multiple jobs with ;" do
27
+ sequence = Whenever::JobSequence.new(:dependent => false)
28
+ sequence << Whenever::Job::Default.new(:task => "first_task", :path => @path)
29
+ sequence << Whenever::Job::Default.new(:task => "second_task", :path => @path)
30
+
31
+ assert_equal sequence.to_single_job.output, "first_task; second_task"
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneypools-whenever
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-11 00:00:00 -06:00
12
+ date: 2009-11-16 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -43,6 +43,7 @@ files:
43
43
  - lib/whenever/base.rb
44
44
  - lib/whenever/command_line.rb
45
45
  - lib/whenever/job_list.rb
46
+ - lib/whenever/job_sequence.rb
46
47
  - lib/whenever/job_types/cap_task.rb
47
48
  - lib/whenever/job_types/default.rb
48
49
  - lib/whenever/job_types/rake_task.rb
@@ -50,8 +51,11 @@ files:
50
51
  - lib/whenever/outputs/cron.rb
51
52
  - lib/whenever/outputs/cron/output_redirection.rb
52
53
  - lib/whenever/version.rb
54
+ - moneypools-whenever.gemspec
53
55
  - test/command_line_test.rb
54
56
  - test/cron_test.rb
57
+ - test/in_sequence_test.rb
58
+ - test/job_sequence_test.rb
55
59
  - test/output_at_test.rb
56
60
  - test/output_cap_test.rb
57
61
  - test/output_command_test.rb
@@ -91,6 +95,8 @@ summary: Clean ruby syntax for defining and deploying messy cron jobs.
91
95
  test_files:
92
96
  - test/command_line_test.rb
93
97
  - test/cron_test.rb
98
+ - test/in_sequence_test.rb
99
+ - test/job_sequence_test.rb
94
100
  - test/output_at_test.rb
95
101
  - test/output_cap_test.rb
96
102
  - test/output_command_test.rb