dtk-action-agent 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d681cedb8361d7119da4a19ac6ad046e008757fc
4
- data.tar.gz: baba1defa66c1a03c3c13b2c791bced412946cdf
3
+ metadata.gz: f72bc2bfeacdd56a05dcd6b9ca7b881b6fa20ba4
4
+ data.tar.gz: f943dcd2ff324eeff690445d8bac30d3f26049af
5
5
  SHA512:
6
- metadata.gz: 168e9ce7a0eb82dc1275dfcb66e752d880e1e4f19a4c732aa8c6cd84319a8fef976dc6479826dcfe529a5dd09fb5f85d9f56870212a32ea44bcff2ad1b266b96
7
- data.tar.gz: f6b627f3b78ae43020c5aae52438ffd938424ab199441a6ec07140b9050b26bc8d7fe030900ea8687f80c36646cdc58ad431d01097e230d17485854a2b8b2859
6
+ metadata.gz: 778beb33c855def060cfbae12933cec49fea2e0e40e503725cf83e5c7a4c49caca7db439176ef1b7326e787af955c8944520dd1e78793c6d0c1c469f89bc19f5
7
+ data.tar.gz: e1957688595c4e0b340841591aa177226f6f7737fae9b778e64050ce90d19420f3e019e97a5e30299edc8ae9e26ef48f2638a084a820cc8b27b78be4a42c8119
data/lib/arbiter.rb CHANGED
@@ -25,7 +25,7 @@ module DTK
25
25
  end
26
26
 
27
27
  def run
28
- return { :results => [], :errors => Log.execution_errrors } if @execution_list.empty?
28
+ return { :results => [], :errors => Log.execution_errors } if @execution_list.empty?
29
29
 
30
30
  # start positioning files
31
31
  @positioner.run()
@@ -34,7 +34,7 @@ module DTK
34
34
  @commander.run()
35
35
 
36
36
  # return results
37
- { :results => @commander.results(), :errors => Log.execution_errrors }
37
+ { :results => @commander.results(), :errors => Log.execution_errors }
38
38
  end
39
39
 
40
40
  end
data/lib/command.rb CHANGED
@@ -81,6 +81,10 @@ module DTK
81
81
  self.process.err
82
82
  end
83
83
 
84
+ def started?
85
+ !!self.process
86
+ end
87
+
84
88
  def to_s
85
89
  "#{@command} (#{command_type})"
86
90
  end
data/lib/commander.rb CHANGED
@@ -5,11 +5,44 @@ module DTK
5
5
  module Agent
6
6
  class Commander
7
7
 
8
+ PARALLEL_EXECUTION = ENV['DTK_ACTION_AGENT_PARALLEL_EXEC'] || false
9
+
8
10
  def initialize(execution_list)
9
11
  @command_tasks = execution_list.collect { |command| Command.new(command) }
10
12
  end
11
13
 
12
14
  def run
15
+ if PARALLEL_EXECUTION
16
+ parallel_run()
17
+ else
18
+ sequential_run()
19
+ end
20
+ end
21
+
22
+ def sequential_run
23
+ @command_tasks.each do |command_task|
24
+ command_task.start_task
25
+
26
+ loop do
27
+ if command_task.exited?
28
+ Log.debug("Command '#{command_task}' finished, with status #{command_task.exitstatus}")
29
+
30
+ # exit if there is an error
31
+ return nil if (command_task.exitstatus.to_i > 0)
32
+
33
+ # if there is a callback start it
34
+ spawn_callback_task(command_task) if command_task.callback_pending?
35
+
36
+ break
37
+ end
38
+
39
+ sleep(1)
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ def parallel_run
13
46
  @command_tasks.each do |command_task|
14
47
  command_task.start_task
15
48
  end
@@ -21,17 +54,13 @@ module DTK
21
54
  # we check status of all tasks
22
55
  # (Usually is not good practice to change array/map you are iterating but this seems as cleanest solutions)
23
56
  @command_tasks.each do |command_task|
24
-
25
57
  # is task finished
26
58
  if command_task.exited?
27
59
  Log.debug("Command '#{command_task}' finished, with status #{command_task.exitstatus}")
28
60
 
29
61
  # if there is a callback start it
30
62
  if command_task.callback_pending?
31
- new_command_task = command_task.spawn_callback_task
32
- new_command_task.start_task
33
- @command_tasks << new_command_task
34
- Log.debug("Command '#{new_command_task}' spawned as callback")
63
+ spawn_callback_task(command_task, true)
35
64
  # new task added we need to check again
36
65
  all_finished = false
37
66
  end
@@ -45,9 +74,16 @@ module DTK
45
74
  end
46
75
  end
47
76
 
77
+ def spawn_callback_task(command_task, start_task = false)
78
+ new_command_task = command_task.spawn_callback_task
79
+ new_command_task.start_task if start_task
80
+ @command_tasks << new_command_task
81
+ Log.debug("Command '#{new_command_task}' spawned as callback")
82
+ end
83
+
48
84
  def results
49
- @command_tasks.collect do |command_task|
50
- process = command_task.process
85
+ res = @command_tasks.collect do |command_task|
86
+ next unless command_task.started?
51
87
  {
52
88
  :status => command_task.exitstatus,
53
89
  :stdout => command_task.out,
@@ -56,6 +92,8 @@ module DTK
56
92
  :child_task => command_task.child_task
57
93
  }
58
94
  end
95
+
96
+ res.compact
59
97
  end
60
98
 
61
99
  private
@@ -1,5 +1,5 @@
1
1
  module DTK
2
2
  module ActionAgent
3
- VERSION="0.0.3"
3
+ VERSION="0.0.4"
4
4
  end
5
5
  end
data/lib/logger.rb CHANGED
@@ -17,7 +17,7 @@ module DTK
17
17
  @error_msgs =[]
18
18
  end
19
19
 
20
- def self.execution_errrors()
20
+ def self.execution_errors()
21
21
  self.instance.error_msgs
22
22
  end
23
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk-action-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich PELAVIN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: posix-spawn
@@ -93,17 +93,17 @@ require_paths:
93
93
  - lib
94
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.2.2
106
+ rubygems_version: 2.4.1
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: DTK Action Agent