task-orchestrator 0.0.7 → 0.0.8
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.md +3 -1
- data/bin/orchestrator +1 -1
- data/examples/failure_handler +3 -1
- data/examples/timeouts +2 -2
- data/lib/orchestrator/task.rb +42 -17
- data/lib/orchestrator/version.rb +1 -1
- metadata +7 -7
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
Simple task orchestration framework driven by Yaml config files
|
4
4
|
|
5
|
-
](https://travis-ci.org/piavlo/task-orchestrator)
|
6
|
+
[](https://gemnasium.com/piavlo/task-orchestrator)
|
7
|
+
[](https://codeclimate.com/github/piavlo/task-orchestrator)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
data/bin/orchestrator
CHANGED
data/examples/failure_handler
CHANGED
@@ -6,6 +6,8 @@ orchestrator:
|
|
6
6
|
steps:
|
7
7
|
- type: sequential
|
8
8
|
scripts:
|
9
|
-
- command:
|
9
|
+
- command: "echo cool"
|
10
|
+
ok_handler: "echo OK Handler"
|
11
|
+
failure_handler: "echo Failure Handler"
|
10
12
|
failure_handler: "echo Step has failed"
|
11
13
|
failure_handler: "echo Task :::ARG.name::: has failed"
|
data/examples/timeouts
CHANGED
data/lib/orchestrator/task.rb
CHANGED
@@ -82,10 +82,15 @@ module Orchestrator
|
|
82
82
|
if command.is_a?(String)
|
83
83
|
command = { 'command' => interpolate_command(command) }
|
84
84
|
elsif command.is_a?(Hash)
|
85
|
-
invalid(error_prefix + " command
|
86
|
-
|
85
|
+
invalid(error_prefix + " is missing command attribute") unless command.has_key?('command')
|
86
|
+
['command', 'ok_handler', 'failure_handler'].each do |attribute|
|
87
|
+
if command.has_key?(attribute)
|
88
|
+
invalid(error_prefix + " #{attribute} attribute is invalid") unless command[attribute].is_a?(String)
|
89
|
+
command[attribute] = interpolate_command(command[attribute])
|
90
|
+
end
|
91
|
+
end
|
87
92
|
else
|
88
|
-
invalid(error_prefix + "
|
93
|
+
invalid(error_prefix + " has invalid format")
|
89
94
|
end
|
90
95
|
command
|
91
96
|
end
|
@@ -154,38 +159,32 @@ module Orchestrator
|
|
154
159
|
) if @options.sms and @options.sms_on_success
|
155
160
|
end
|
156
161
|
|
157
|
-
def
|
162
|
+
def run_command(command,timeout)
|
158
163
|
result = ""
|
159
164
|
error = ""
|
160
165
|
|
161
|
-
timeout = script.has_key?('timeout') ? script['timeout'].to_i : @timeout
|
162
|
-
|
163
|
-
script['status'] = 'STARTED'
|
164
|
-
save_state
|
165
|
-
|
166
166
|
# start = Time.now
|
167
|
-
|
167
|
+
|
168
|
+
status = 'STARTED'
|
168
169
|
begin
|
169
170
|
Timeout::timeout(timeout) do
|
170
|
-
status = POpen4::popen4(
|
171
|
+
status = POpen4::popen4(command) do |stdout, stderr, stdin, pid|
|
171
172
|
result = stdout.read.strip
|
172
173
|
error = stderr.read.strip
|
173
174
|
end
|
174
|
-
|
175
|
+
status = (status.nil? or status.exitstatus != 0) ? 'FAILED' : 'OK'
|
175
176
|
end
|
176
177
|
rescue Timeout::Error
|
177
|
-
|
178
|
+
status = 'TIMEOUT'
|
178
179
|
end
|
179
180
|
|
180
|
-
save_state
|
181
|
-
|
182
181
|
# runtime = Time.now - start
|
183
182
|
# runtime = runtime > 60 ? runtime/60 : runtime
|
184
183
|
|
185
184
|
@mutex.synchronize do
|
186
185
|
output = <<-EOF
|
187
186
|
|
188
|
-
Running: #{
|
187
|
+
Running: #{command} - #{status}
|
189
188
|
============ STDOUT ============
|
190
189
|
#{result}
|
191
190
|
============ STDERR ============
|
@@ -197,7 +196,31 @@ EOF
|
|
197
196
|
puts output if @options.verbose
|
198
197
|
end
|
199
198
|
|
200
|
-
|
199
|
+
return status
|
200
|
+
end
|
201
|
+
|
202
|
+
def run_post_script_handlers(script,status)
|
203
|
+
handler = nil
|
204
|
+
if status
|
205
|
+
handler = 'ok_handler' if script.has_key?('ok_handler')
|
206
|
+
else
|
207
|
+
handler = 'failure_handler' if script.has_key?('failure_handler')
|
208
|
+
end
|
209
|
+
if handler
|
210
|
+
timeout = script.has_key?('timeout') ? script['timeout'].to_i : @timeout
|
211
|
+
run_command(script[handler],timeout)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def run_script(script)
|
216
|
+
timeout = script.has_key?('timeout') ? script['timeout'].to_i : @timeout
|
217
|
+
|
218
|
+
script['status'] = 'STARTED'
|
219
|
+
save_state
|
220
|
+
script['status'] = run_command(script['command'],timeout)
|
221
|
+
save_state
|
222
|
+
|
223
|
+
return script['status'] == 'OK'
|
201
224
|
end
|
202
225
|
|
203
226
|
def thread_wrapper(i,script)
|
@@ -231,6 +254,7 @@ EOF
|
|
231
254
|
end
|
232
255
|
|
233
256
|
@threads.delete(i)
|
257
|
+
run_post_script_handlers(script,@statuses[i])
|
234
258
|
fail if @on_failure == :die and not @statuses[i]
|
235
259
|
end
|
236
260
|
|
@@ -295,6 +319,7 @@ EOF
|
|
295
319
|
break if failures > @retries
|
296
320
|
sleep @retry_delay
|
297
321
|
end
|
322
|
+
run_post_script_handlers(step['scripts'][index],@statuses[index])
|
298
323
|
fail if not @statuses[index] and @on_failure == :die
|
299
324
|
end
|
300
325
|
fail if @on_failure != :ignore and @statuses.find_index(false)
|
data/lib/orchestrator/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: task-orchestrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pony
|
@@ -85,16 +85,16 @@ extra_rdoc_files: []
|
|
85
85
|
files:
|
86
86
|
- bin/orchestrator
|
87
87
|
- lib/orchestrator.rb
|
88
|
-
- lib/orchestrator/task.rb
|
89
88
|
- lib/orchestrator/version.rb
|
90
89
|
- lib/orchestrator/cli.rb
|
90
|
+
- lib/orchestrator/task.rb
|
91
|
+
- examples/timeouts
|
92
|
+
- examples/interpolation
|
93
|
+
- examples/dependencies
|
91
94
|
- examples/sequential
|
92
95
|
- examples/failure_handler
|
93
|
-
- examples/multistep
|
94
96
|
- examples/parallel
|
95
|
-
- examples/
|
96
|
-
- examples/timeouts
|
97
|
-
- examples/dependencies
|
97
|
+
- examples/multistep
|
98
98
|
- task-orchestrator.gemspec
|
99
99
|
- LICENSE
|
100
100
|
- README.md
|