foreman-tasks 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/app/lib/actions/base.rb +1 -1
- data/app/lib/actions/helpers/args_serialization.rb +5 -24
- data/app/lib/actions/helpers/lock.rb +15 -31
- data/app/models/foreman_tasks/task/dynflow_task.rb +1 -7
- data/lib/foreman_tasks.rb +10 -3
- data/lib/foreman_tasks/triggers.rb +1 -1
- data/lib/foreman_tasks/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -10,8 +10,8 @@ Installation
|
|
10
10
|
Put the following to your Foreman's bundle.d/Gemfile.local.rb:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem 'dynflow',
|
14
|
-
gem 'foreman-tasks', :git => '
|
13
|
+
gem 'dynflow', :git => 'https://github.com/Dynflow/dynflow.git'
|
14
|
+
gem 'foreman-tasks', :git => 'https://github.com/iNecas/foreman-tasks.git'
|
15
15
|
```
|
16
16
|
|
17
17
|
Run:
|
data/app/lib/actions/base.rb
CHANGED
@@ -17,7 +17,7 @@ module Actions
|
|
17
17
|
|
18
18
|
# This method should return humanized description of the action, e.g. "Install Package"
|
19
19
|
def humanized_name
|
20
|
-
|
20
|
+
self.class.name[/\w+$/].gsub(/([a-z])([A-Z])/) { "#{$1} #{$2}" }
|
21
21
|
end
|
22
22
|
|
23
23
|
# This method should return String of Array<String> describing input for the task
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module Actions
|
2
2
|
module Helpers
|
3
3
|
module ArgsSerialization
|
4
|
-
def self.included(base)
|
5
|
-
base.extend(ClassMethods)
|
6
|
-
end
|
7
|
-
|
8
4
|
class Builder
|
9
5
|
attr_reader :hash
|
10
6
|
def initialize(*objects)
|
@@ -22,7 +18,7 @@ module Actions
|
|
22
18
|
unless object.respond_to?(:action_input_key)
|
23
19
|
raise "Serialized model has to repond to :action_input_key method"
|
24
20
|
end
|
25
|
-
key
|
21
|
+
key = object.action_input_key
|
26
22
|
value = object_to_value(object)
|
27
23
|
add(key, value)
|
28
24
|
when Hash
|
@@ -45,7 +41,7 @@ module Actions
|
|
45
41
|
raise "Serialized model has to repond to :to_action_input method"
|
46
42
|
end
|
47
43
|
object.to_action_input
|
48
|
-
when String, Numeric, true, false, nil
|
44
|
+
when String, Numeric, true, false, nil, Dynflow::ExecutionPlan::OutputReference
|
49
45
|
object
|
50
46
|
else
|
51
47
|
object.to_s
|
@@ -66,24 +62,9 @@ module Actions
|
|
66
62
|
end
|
67
63
|
end
|
68
64
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
super.tap do |phase_class|
|
73
|
-
if phase_module == Dynflow::Action::PlanPhase
|
74
|
-
phase_class.send(:include, PlanMethods)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
module PlanMethods
|
82
|
-
|
83
|
-
def serialize_args(*objects)
|
84
|
-
Builder.new(*objects).hash
|
85
|
-
end
|
86
|
-
|
65
|
+
def serialize_args(*objects)
|
66
|
+
phase! Dynflow::Action::Plan
|
67
|
+
Builder.new(*objects).hash
|
87
68
|
end
|
88
69
|
end
|
89
70
|
end
|
@@ -1,42 +1,26 @@
|
|
1
1
|
module Actions
|
2
2
|
module Helpers
|
3
3
|
module Lock
|
4
|
-
def
|
5
|
-
|
4
|
+
def task
|
5
|
+
::ForemanTasks::Task::DynflowTask.find_by_external_id!(execution_plan_id)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
if phase_module == Dynflow::Action::PlanPhase
|
13
|
-
phase_class.send(:include, PlanMethods)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
8
|
+
# @see Lock.exclusive!
|
9
|
+
def exclusive_lock!(resource)
|
10
|
+
phase! Dynflow::Action::Plan
|
11
|
+
::ForemanTasks::Lock.exclusive!(resource, task.id)
|
18
12
|
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
# @see Lock.exclusive!
|
27
|
-
def exclusive_lock!(resource)
|
28
|
-
::ForemanTasks::Lock.exclusive!(resource, task.id)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @see Lock.lock!
|
32
|
-
def lock!(resource, *lock_names)
|
33
|
-
::ForemanTasks::Lock.lock!(resource, task.id, *lock_names.flatten)
|
34
|
-
end
|
14
|
+
# @see Lock.lock!
|
15
|
+
def lock!(resource, *lock_names)
|
16
|
+
phase! Dynflow::Action::Plan
|
17
|
+
::ForemanTasks::Lock.lock!(resource, task.id, *lock_names.flatten)
|
18
|
+
end
|
35
19
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
20
|
+
# @see Lock.link!
|
21
|
+
def link!(resource)
|
22
|
+
phase! Dynflow::Action::Plan
|
23
|
+
::ForemanTasks::Lock.link!(resource, task.id)
|
40
24
|
end
|
41
25
|
end
|
42
26
|
end
|
@@ -13,7 +13,7 @@ module ForemanTasks
|
|
13
13
|
# load extra data, there is place for optimization on Dynflow side
|
14
14
|
# if needed (getting more keys into the data value)
|
15
15
|
unless self.label
|
16
|
-
self.label = main_action.
|
16
|
+
self.label = main_action.class.name
|
17
17
|
end
|
18
18
|
update_progress
|
19
19
|
end
|
@@ -28,12 +28,6 @@ module ForemanTasks
|
|
28
28
|
@execution_plan ||= ForemanTasks.dynflow.world.persistence.load_execution_plan(external_id)
|
29
29
|
end
|
30
30
|
|
31
|
-
def main_action
|
32
|
-
return @main_action if @main_action
|
33
|
-
main_action_id = execution_plan.root_plan_step.action_id
|
34
|
-
@main_action = execution_plan.actions.find { |action| action.id == main_action_id }
|
35
|
-
end
|
36
|
-
|
37
31
|
def input
|
38
32
|
main_action.respond_to?(:task_input) && main_action.task_input
|
39
33
|
end
|
data/lib/foreman_tasks.rb
CHANGED
@@ -5,6 +5,7 @@ require 'foreman_tasks/triggers'
|
|
5
5
|
|
6
6
|
module ForemanTasks
|
7
7
|
extend Algebrick::TypeCheck
|
8
|
+
extend Algebrick::Matching
|
8
9
|
|
9
10
|
def self.dynflow
|
10
11
|
@dynflow ||= ForemanTasks::Dynflow.new
|
@@ -17,9 +18,15 @@ module ForemanTasks
|
|
17
18
|
def self.trigger_task(async, action, *args, &block)
|
18
19
|
Match! async, true, false
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
match trigger(action, *args, &block),
|
22
|
+
(on ::Dynflow::World::PlaningFailed.(error: ~any) |
|
23
|
+
::Dynflow::World::ExecutionFailed.(error: ~any) do |error|
|
24
|
+
raise error
|
25
|
+
end),
|
26
|
+
(on ::Dynflow::World::Triggered.(execution_plan_id: ~any, future: ~any) do |id, finished|
|
27
|
+
finished.wait if async == false
|
28
|
+
ForemanTasks::Task::DynflowTask.find_by_external_id!(id)
|
29
|
+
end)
|
23
30
|
end
|
24
31
|
|
25
32
|
def self.async_task(action, *args, &block)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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: 2014-02-
|
12
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|