taskmaster 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.rdoc +12 -1
- data/VERSION +1 -1
- data/lib/taskmaster.rb +7 -1
- data/lib/taskmaster/henchman.rb +8 -3
- data/lib/taskmaster/railtie.rb +12 -0
- data/lib/tasks/taskmaster.rake +8 -0
- data/rails/init.rb +1 -0
- data/taskmaster.gemspec +9 -6
- data/test/classes/foot_soldier.rb +64 -0
- data/test/helper.rb +1 -1
- data/test/test_henchman.rb +27 -2
- data/test/test_taskmaster.rb +5 -1
- metadata +21 -18
- data/test/foot_soldier.rb +0 -9
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -5,6 +5,8 @@ Make your Ruby classes cron-aware!
|
|
5
5
|
|
6
6
|
== Example
|
7
7
|
|
8
|
+
The base case is simple -- just include the `Taskmaster::Henchman` module, define a `run` class method, and use `whenever` syntax to specify when and how often the method should run:
|
9
|
+
|
8
10
|
require 'taskmaster'
|
9
11
|
|
10
12
|
class FootSoldier
|
@@ -19,9 +21,18 @@ Make your Ruby classes cron-aware!
|
|
19
21
|
|
20
22
|
puts FootSoldier.cron_output # => "5,15,25,35,45,55 * * * * /bin/bash -l -c 'cd /... && script/runner -e production '\''BulkTask.run'\'''"
|
21
23
|
|
24
|
+
You can override various pieces of this, including the name of the class method to run:
|
25
|
+
|
26
|
+
every 10.minutes, :run => :special_method
|
27
|
+
|
28
|
+
def self.special_method
|
29
|
+
# I'm not the default!
|
30
|
+
end
|
31
|
+
|
32
|
+
Check the documentation on `Taskmaster::Henchman.every` for details on all the allowed options.
|
33
|
+
|
22
34
|
== TODO
|
23
35
|
|
24
|
-
* figure out different task types
|
25
36
|
* add a Rake task to output and save crontab for all Taskmaster-including classes (fall back to whenever)
|
26
37
|
|
27
38
|
== Contributing to taskmaster
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.1
|
data/lib/taskmaster.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'whenever'
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'taskmaster/henchman'
|
4
|
+
require 'taskmaster/railtie'
|
4
5
|
|
5
6
|
module Taskmaster
|
6
7
|
def self.cron_output
|
8
|
+
# make sure all the models that could include Henchman are loaded
|
9
|
+
if defined?(Rails)
|
10
|
+
Dir[Rails.root.join('app', 'models', '**', '*.rb')].each { |file| require file }
|
11
|
+
end
|
12
|
+
|
7
13
|
Henchman.included_in.map { |klass| klass.cron_output.strip }.join("\n")
|
8
14
|
end
|
9
15
|
end
|
data/lib/taskmaster/henchman.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'taskmaster'
|
2
|
+
|
1
3
|
module Taskmaster
|
2
4
|
module Henchman
|
3
5
|
def self.included(base)
|
@@ -13,8 +15,11 @@ module Taskmaster
|
|
13
15
|
|
14
16
|
module ClassMethods
|
15
17
|
def every(frequency, options = {})
|
16
|
-
@
|
17
|
-
|
18
|
+
@scheduled_jobs ||= []
|
19
|
+
method = options.delete(:run) || :run
|
20
|
+
command = options.delete(:command) || :runner
|
21
|
+
@scheduled_jobs << "every #{frequency.to_s}, #{options.inspect} do
|
22
|
+
#{command.to_s} \'#{self.name}.#{method.to_s}\'
|
18
23
|
end"
|
19
24
|
end
|
20
25
|
|
@@ -23,7 +28,7 @@ end"
|
|
23
28
|
end
|
24
29
|
|
25
30
|
def cron_output
|
26
|
-
Whenever::JobList.new(@
|
31
|
+
Whenever::JobList.new(@scheduled_jobs.join("\n")).generate_cron_output
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'taskmaster/railtie'
|
data/taskmaster.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{taskmaster}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Scofield"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-17}
|
13
13
|
s.description = %q{Taskmaster allows you to easily make your Ruby classes aware of cron.}
|
14
14
|
s.email = %q{git@turrean.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,8 +25,11 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"lib/taskmaster.rb",
|
27
27
|
"lib/taskmaster/henchman.rb",
|
28
|
+
"lib/taskmaster/railtie.rb",
|
29
|
+
"lib/tasks/taskmaster.rake",
|
30
|
+
"rails/init.rb",
|
28
31
|
"taskmaster.gemspec",
|
29
|
-
"test/foot_soldier.rb",
|
32
|
+
"test/classes/foot_soldier.rb",
|
30
33
|
"test/helper.rb",
|
31
34
|
"test/test_henchman.rb",
|
32
35
|
"test/test_taskmaster.rb"
|
@@ -42,14 +45,14 @@ Gem::Specification.new do |s|
|
|
42
45
|
|
43
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
47
|
s.add_runtime_dependency(%q<whenever>, [">= 0"])
|
45
|
-
s.add_runtime_dependency(%q<activesupport>, ["
|
48
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
46
49
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
50
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
48
51
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
52
|
s.add_development_dependency(%q<rake>, ["= 0.8.7"])
|
50
53
|
else
|
51
54
|
s.add_dependency(%q<whenever>, [">= 0"])
|
52
|
-
s.add_dependency(%q<activesupport>, ["
|
55
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
53
56
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
57
|
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
55
58
|
s.add_dependency(%q<rcov>, [">= 0"])
|
@@ -57,7 +60,7 @@ Gem::Specification.new do |s|
|
|
57
60
|
end
|
58
61
|
else
|
59
62
|
s.add_dependency(%q<whenever>, [">= 0"])
|
60
|
-
s.add_dependency(%q<activesupport>, ["
|
63
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
61
64
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
65
|
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
63
66
|
s.add_dependency(%q<rcov>, [">= 0"])
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class FootSoldier
|
2
|
+
include Taskmaster::Henchman
|
3
|
+
|
4
|
+
every 10.minutes
|
5
|
+
|
6
|
+
def self.run
|
7
|
+
# get beaten up by a superhero
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class SpecialSoldier
|
12
|
+
include Taskmaster::Henchman
|
13
|
+
|
14
|
+
every 1.hour, :run => :specialty
|
15
|
+
|
16
|
+
def self.specialty
|
17
|
+
# run this one
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class MultiSoldier
|
22
|
+
include Taskmaster::Henchman
|
23
|
+
|
24
|
+
every 1.minute
|
25
|
+
every 1.hour, :run => :specialty
|
26
|
+
|
27
|
+
def self.specialty
|
28
|
+
# run this one
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.run
|
32
|
+
# do something cool
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class SpecificSoldier
|
37
|
+
include Taskmaster::Henchman
|
38
|
+
|
39
|
+
every 1.hour, :at => 20
|
40
|
+
|
41
|
+
def self.run
|
42
|
+
# get beaten up by a superhero
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class CommandSoldier
|
47
|
+
include Taskmaster::Henchman
|
48
|
+
|
49
|
+
every 1.hour, :command => :command
|
50
|
+
|
51
|
+
def self.run
|
52
|
+
# nothing to see here
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class FrequencySoldier
|
57
|
+
include Taskmaster::Henchman
|
58
|
+
|
59
|
+
every 1.hour, :command => :command
|
60
|
+
|
61
|
+
def self.run
|
62
|
+
# nothing to see here
|
63
|
+
end
|
64
|
+
end
|
data/test/helper.rb
CHANGED
data/test/test_henchman.rb
CHANGED
@@ -1,13 +1,38 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestHenchman < Test::Unit::TestCase
|
4
4
|
def test_class_should_be_definable
|
5
5
|
assert_nothing_raised do
|
6
6
|
FootSoldier
|
7
|
+
SpecialSoldier
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
+
def test_the_base_case_should_work
|
11
12
|
assert_equal "0,10,20,30,40,50 * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''FootSoldier.run'\\'''", FootSoldier.cron_output.strip
|
12
13
|
end
|
14
|
+
|
15
|
+
def test_scheduled_methods_should_be_overradble
|
16
|
+
assert_equal "0 * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''SpecialSoldier.specialty'\\'''", SpecialSoldier.cron_output.strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_multiple_tasks_can_live_in_a_class
|
20
|
+
output = MultiSoldier.cron_output.split(/\n+/)
|
21
|
+
assert_equal 2, output.size
|
22
|
+
|
23
|
+
assert_equal "* * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''MultiSoldier.run'\\'''", output[0]
|
24
|
+
assert_equal "0 * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''MultiSoldier.specialty'\\'''", output[1]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_whenever_options_should_be_respected
|
28
|
+
assert_equal "20 * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''SpecificSoldier.run'\\'''", SpecificSoldier.cron_output.strip
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_different_whenever_commands_should_be_usable
|
32
|
+
assert_equal "0 * * * * /bin/bash -l -c 'CommandSoldier.run'", CommandSoldier.cron_output.strip
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_whenever_alternative_names_should_be_usable
|
36
|
+
assert_equal "0 * * * * /bin/bash -l -c 'FrequencySoldier.run'", FrequencySoldier.cron_output.strip
|
37
|
+
end
|
13
38
|
end
|
data/test/test_taskmaster.rb
CHANGED
@@ -9,6 +9,10 @@ class TestTaskmaster < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_taskmaster_should_know_all_output
|
12
|
-
|
12
|
+
output = Taskmaster.cron_output.split(/\n+/)
|
13
|
+
assert_equal "0,10,20,30,40,50 * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''FootSoldier.run'\\'''", output[0]
|
14
|
+
assert_equal "0 * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''SpecialSoldier.specialty'\\'''", output[1]
|
15
|
+
assert_equal "* * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''MultiSoldier.run'\\'''", output[2]
|
16
|
+
assert_equal "0 * * * * /bin/bash -l -c 'cd /Users/benscofield/personal/util/taskmaster && script/runner -e production '\\''MultiSoldier.specialty'\\'''", output[3]
|
13
17
|
end
|
14
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taskmaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-17 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: whenever
|
17
|
-
requirement: &
|
17
|
+
requirement: &2152144960 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,21 +22,21 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2152144960
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &2152143680 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2152143680
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &2152142280 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2152142280
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: jeweler
|
50
|
-
requirement: &
|
50
|
+
requirement: &2152140880 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.6.2
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2152140880
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rcov
|
61
|
-
requirement: &
|
61
|
+
requirement: &2152139660 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2152139660
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rake
|
72
|
-
requirement: &
|
72
|
+
requirement: &2152138620 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - =
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: 0.8.7
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2152138620
|
81
81
|
description: Taskmaster allows you to easily make your Ruby classes aware of cron.
|
82
82
|
email: git@turrean.com
|
83
83
|
executables: []
|
@@ -94,8 +94,11 @@ files:
|
|
94
94
|
- VERSION
|
95
95
|
- lib/taskmaster.rb
|
96
96
|
- lib/taskmaster/henchman.rb
|
97
|
+
- lib/taskmaster/railtie.rb
|
98
|
+
- lib/tasks/taskmaster.rake
|
99
|
+
- rails/init.rb
|
97
100
|
- taskmaster.gemspec
|
98
|
-
- test/foot_soldier.rb
|
101
|
+
- test/classes/foot_soldier.rb
|
99
102
|
- test/helper.rb
|
100
103
|
- test/test_henchman.rb
|
101
104
|
- test/test_taskmaster.rb
|
@@ -115,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
118
|
version: '0'
|
116
119
|
segments:
|
117
120
|
- 0
|
118
|
-
hash:
|
121
|
+
hash: -4405291791740595885
|
119
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
123
|
none: false
|
121
124
|
requirements:
|