task-orchestrator 0.0.5 → 0.0.6

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Simple task orchestration framework driven by Yaml config files
4
4
 
5
+ ![travis](https://secure.travis-ci.org/piavlo/task-orchestrator.png)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -0,0 +1,11 @@
1
+ orchestrator:
2
+ statedir: states
3
+ failure_handler:
4
+ description: failure handler test
5
+ save: true
6
+ steps:
7
+ - type: sequential
8
+ scripts:
9
+ - exit 0
10
+ failure_handler: "echo Step has failed"
11
+ failure_handler: "echo Task :::ARG.name::: has failed"
data/examples/sequential CHANGED
@@ -1,7 +1,7 @@
1
1
  orchestrator:
2
2
  statedir: states
3
3
  sequential:
4
- description: lalalalal
4
+ description: sequential test
5
5
  save: true
6
6
  steps:
7
7
  - type: sequential
@@ -78,7 +78,19 @@ module Orchestrator
78
78
  end
79
79
  end
80
80
 
81
+ def validate_command(command,error_prefix)
82
+ if command.is_a?(String)
83
+ command = { 'command' => interpolate_command(command) }
84
+ elsif command.is_a?(Hash)
85
+ invalid(error_prefix + " command is invalid") unless command.has_key?('command') && command.is_a?(String)
86
+ command['command'] = interpolate_command(command['command'])
87
+ else
88
+ invalid(error_prefix + " is invalid")
89
+ end
90
+ end
91
+
81
92
  def validate_config
93
+ @state['failure_handler'] = validate_command(@state['failure_handler'], 'task failure handler') if @state.has_key?('failure_handler')
82
94
  if @state.has_key?('email')
83
95
  invalid("config email recipients is missing or invalid") unless @state['email'].has_key?('recipients') && @state['email']['recipients'].is_a?(String) || @state['email']['recipients'].is_a?(Array)
84
96
  invalid("config email from is missing or invalid") unless @state['email'].has_key?('from') && @state['email']['from'].is_a?(String)
@@ -97,21 +109,16 @@ module Orchestrator
97
109
  invalid("task step has no type") unless step.has_key?('type') && step['type'].is_a?(String)
98
110
  invalid("task step type #{step['type']} is invalid") unless [:parallel,:sequential].find_index(step['type'].to_sym)
99
111
  invalid("task step scripts is missing or invalid") unless step.has_key?('scripts') && step['scripts'].is_a?(Array)
112
+ step['failure_handler'] = validate_command(step['failure_handler'], 'task failure handler') if step.has_key?('failure_handler')
100
113
  step['scripts'].each_index do |index|
101
- if step['scripts'][index].is_a?(String)
102
- step['scripts'][index] = { 'command' => interpolate_command(step['scripts'][index]) }
103
- elsif step['scripts'][index].is_a?(Hash)
104
- invalid("task step script command is invalid") unless step['scripts'][index].has_key?('command') && step['scripts'][index]['command'].is_a?(String)
105
- step['scripts'][index]['command'] = interpolate_command(step['scripts'][index]['command'])
106
- else
107
- invalid("task script is invalid")
108
- end
114
+ step['scripts'][index] = validate_command(step['scripts'][index], 'task step script')
109
115
  end
110
116
  end
111
117
  end
112
118
 
113
119
  def fail
114
- system "#{@state['failure_handler']} #{@state['failure_handler_args']}" if @state.has_key?('failure_handler')
120
+ run_script(@failure_handler) if @failure_handler
121
+ run_script(@state['failure_handler']) if @state.has_key?('failure_handler')
115
122
 
116
123
  Pony.mail(
117
124
  :to => @state['email']['recipients'],
@@ -238,12 +245,13 @@ EOF
238
245
  @retry_delay = step.has_key?('retry_delay') ? step['retry_delay'] : 0
239
246
  @on_week_days = step.has_key?('on_week_days') ? step['on_week_days'].map{|d| "#{d}?".downcase.to_sym} : [ :sunday?, :monday?, :tuesday?, :wednesday?, :thursday?, :friday?, :saturday? ]
240
247
  @on_month_days = step.has_key?('on_month_days') ? step['on_month_days'] : (1..31).to_a
248
+ @failure_handler = step.has_key?('failure_handler') ? step['failure_handler'] : nil
241
249
 
242
250
  if step['type'].to_sym == :parallel and @on_week_days.map {|d| Time.now.send(d) }.find_index(true) and @on_month_days.find_index(Time.now.mday)
243
251
  #Parallel
244
252
  interval = step.has_key?('sleep') ? step['sleep'] : 1
245
- @on_failure = step.has_key?('on_failure') ? step['on_failure'].to_sym : :finish
246
253
  parallel_factor = step.has_key?('parallel') ? step['parallel'] : 1
254
+ @on_failure = step.has_key?('on_failure') ? step['on_failure'].to_sym : :finish
247
255
 
248
256
  @threads = Hash.new
249
257
  index = 0
@@ -1,3 +1,3 @@
1
1
  module Orchestrator
2
- VERSION ||= '0.0.5'
2
+ VERSION ||= '0.0.6'
3
3
  end
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.5
4
+ version: 0.0.6
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-01-08 00:00:00.000000000 Z
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pony
@@ -89,6 +89,7 @@ files:
89
89
  - lib/orchestrator/version.rb
90
90
  - lib/orchestrator/cli.rb
91
91
  - examples/sequential
92
+ - examples/failure_handler
92
93
  - examples/multistep
93
94
  - examples/parallel
94
95
  - examples/interpolation