gregfitz23-chrono_trigger 0.0.5 → 0.1.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.
- data/README.rdoc +2 -1
- data/VERSION.yml +2 -2
- data/lib/chrono_trigger.rb +1 -1
- data/lib/chrono_trigger/process.rb +13 -0
- data/lib/chrono_trigger/runner.rb +23 -7
- data/lib/chrono_trigger/shell.rb +0 -1
- data/lib/chrono_trigger/trigger.rb +0 -1
- data/lib/triggers/test_triggers.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -13,13 +13,14 @@ A cron framework for defining cron tasks using a readable DSL.
|
|
13
13
|
Create trigger files (by default in the lib/triggers) directory.
|
14
14
|
Triggers should follow the pattern:
|
15
15
|
|
16
|
+
do
|
16
17
|
trigger "name" do
|
17
18
|
runs { code to execute }
|
18
19
|
on :monday
|
19
20
|
every :minutes=>10
|
20
21
|
at :hour=>9, :minute=>[30,50]
|
21
22
|
end
|
22
|
-
|
23
|
+
end
|
23
24
|
Run chrono_trigger -t{full path to trigger file}
|
24
25
|
|
25
26
|
== REQUIREMENTS:
|
data/VERSION.yml
CHANGED
data/lib/chrono_trigger.rb
CHANGED
@@ -4,6 +4,8 @@ module ChronoTrigger
|
|
4
4
|
|
5
5
|
def run(options={})
|
6
6
|
@t = Thread.new do
|
7
|
+
setup(options)
|
8
|
+
|
7
9
|
shell = ChronoTrigger::Shell.new
|
8
10
|
shell.load_triggers(options[:trigger_file])
|
9
11
|
loop do
|
@@ -18,5 +20,16 @@ module ChronoTrigger
|
|
18
20
|
def stop
|
19
21
|
@t.exit
|
20
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def setup(options={})
|
26
|
+
if application_context = options[:application_context]
|
27
|
+
ENV['RAILS_ENV'] = options[:env] || "development"
|
28
|
+
|
29
|
+
application_path = File.join(application_context, 'config', 'environment')
|
30
|
+
STDOUT.puts "Loading application environment at #{File.join(application_context, 'config', 'environment')} for '#{ENV['RAILS_ENV']}' enviroment."
|
31
|
+
require(application_path)
|
32
|
+
end
|
33
|
+
end
|
21
34
|
end
|
22
35
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'process')
|
2
|
-
require "
|
2
|
+
require "logger"
|
3
3
|
require 'optparse'
|
4
4
|
require 'yaml'
|
5
5
|
|
@@ -31,7 +31,7 @@ module ChronoTrigger
|
|
31
31
|
pid = @process.running?
|
32
32
|
if pid
|
33
33
|
if options[:force]
|
34
|
-
|
34
|
+
STDOUT.puts "Shutting down existing ChronoTrigger."
|
35
35
|
@process.kill
|
36
36
|
@process = ProcessHelper.new(options[:logger], options[:pid_file], options[:user], options[:group])
|
37
37
|
else
|
@@ -49,13 +49,14 @@ module ChronoTrigger
|
|
49
49
|
self.options = {
|
50
50
|
:log_level => Logger::INFO,
|
51
51
|
:daemonize => false,
|
52
|
-
:pid_file => File.join('', 'var', 'run', 'chrono_trigger.pid')
|
52
|
+
:pid_file => File.join('', 'var', 'run', 'chrono_trigger.pid'),
|
53
|
+
:env => "development"
|
53
54
|
}
|
54
55
|
|
55
56
|
OptionParser.new do |opts|
|
56
57
|
opts.summary_width = 25
|
57
58
|
|
58
|
-
opts.banner = "ChronoTrigger\n\n",
|
59
|
+
opts.banner = "ChronoTrigger - Execute cron jobs within the context of a Rails application\n\n",
|
59
60
|
"usage: chrono_trigger [options...]\n",
|
60
61
|
" chrono_trigger --help\n",
|
61
62
|
" chrono_trigger --version\n"
|
@@ -63,18 +64,29 @@ module ChronoTrigger
|
|
63
64
|
opts.separator ""
|
64
65
|
opts.separator ""; opts.separator "ChronoTrigger Options:"
|
65
66
|
|
66
|
-
opts.on("-tTRIGGER_FILE", "--triggers TRIGGERS", "Path to file specifying triggers to be executed") do |trigger_file|
|
67
|
+
opts.on("-tTRIGGER_FILE", "--triggers TRIGGERS", "Path to file specifying triggers to be executed. When also specifying -a, this path will be relative to the application path") do |trigger_file|
|
67
68
|
options[:trigger_file] = trigger_file
|
68
69
|
end
|
69
70
|
|
70
|
-
opts.on("-f", "--force", "Force restart of ChronoTrigger process.") do
|
71
|
+
opts.on("-f", "--force", "Force restart of ChronoTrigger process (can be used in conjunction with -P).") do
|
71
72
|
options[:force] = true
|
72
73
|
end
|
73
74
|
|
74
|
-
opts.on("-s", "--stop", "Stop a currently running ChronoTrigger process.") do
|
75
|
+
opts.on("-s", "--stop", "Stop a currently running ChronoTrigger process (can be used in conjunction with -P).") do
|
75
76
|
options[:stop] = true
|
76
77
|
end
|
77
78
|
|
79
|
+
opts.separator ""
|
80
|
+
opts.separator ""; opts.separator "Rails options:"
|
81
|
+
|
82
|
+
opts.on("-aAPPLICATION", "--application RAILS", "Path to Rails application context to execture triggers in.") do |application_context|
|
83
|
+
options[:application_context] = application_context
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on("-eENVIRONMENT", "--environment ENVIRONMENT", "Rails environment to execute triggers in.") do |environment|
|
87
|
+
options[:env] = environment
|
88
|
+
end
|
89
|
+
|
78
90
|
opts.separator ""
|
79
91
|
opts.separator ""; opts.separator "Process:"
|
80
92
|
|
@@ -111,6 +123,10 @@ module ChronoTrigger
|
|
111
123
|
|
112
124
|
@process.daemonize if options[:daemonize]
|
113
125
|
|
126
|
+
if application_context = options[:application_context]
|
127
|
+
Dir.chdir(application_context)
|
128
|
+
end
|
129
|
+
|
114
130
|
setup_signal_traps
|
115
131
|
@process.write_pid_file
|
116
132
|
|
data/lib/chrono_trigger/shell.rb
CHANGED