foreman-tasks 0.1.3 → 0.1.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.
@@ -3,12 +3,14 @@ module Actions
3
3
 
4
4
  class Humanizer
5
5
 
6
- PARTS_ORDER = [:repository,
6
+ PARTS_ORDER = [:user,
7
+ :repository,
7
8
  :product,
8
9
  :system,
9
10
  :organization]
10
11
  # Just to get the trings into pot file
11
- PARTS_TRANSLATIONS = [N_('repository'),
12
+ PARTS_TRANSLATIONS = [N_('user'),
13
+ N_('repository'),
12
14
  N_('product'),
13
15
  N_('system'),
14
16
  N_('organization')]
@@ -5,6 +5,10 @@ module ForemanTasks
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
+ before_create :before_plan_action
9
+ before_update :before_plan_action
10
+ before_destroy :before_plan_action
11
+
8
12
  after_create :plan_create_action
9
13
  after_update :plan_update_action
10
14
  after_destroy :plan_destroy_action
@@ -52,6 +56,17 @@ module ForemanTasks
52
56
  return result
53
57
  end
54
58
 
59
+ # dynflow actions are async by default
60
+ def before_plan_action
61
+ @dynflow_sync_action = false
62
+ return true
63
+ end
64
+
65
+ # to make the triggered action synchronous
66
+ def sync_action!
67
+ @dynflow_sync_action = true
68
+ end
69
+
55
70
  def create_action
56
71
  end
57
72
 
@@ -93,7 +108,8 @@ module ForemanTasks
93
108
  # Execute the prepared execution plan after the db transaction was commited
94
109
  def execute_planned_action
95
110
  if @execution_plan
96
- ::ForemanTasks.dynflow.world.execute(@execution_plan.id)
111
+ run = ::ForemanTasks.dynflow.world.execute(@execution_plan.id)
112
+ run.finished.wait if @dynflow_sync_action
97
113
  end
98
114
  return true
99
115
  end
data/lib/foreman_tasks.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'foreman_tasks/version'
2
2
  require 'foreman_tasks/engine'
3
3
  require 'foreman_tasks/dynflow'
4
+ require 'foreman_tasks/triggers'
4
5
 
5
6
  module ForemanTasks
7
+ extend Algebrick::TypeCheck
6
8
 
7
9
  def self.dynflow
8
10
  @dynflow ||= ForemanTasks::Dynflow.new
@@ -12,9 +14,21 @@ module ForemanTasks
12
14
  dynflow.world.trigger action, *args, &block
13
15
  end
14
16
 
15
- def self.async_task(action, *args, &block)
17
+ def self.trigger_task(async, action, *args, &block)
18
+ Match! async, true, false
19
+
16
20
  run = trigger(action, *args, &block)
17
- ForemanTasks::Task::DynflowTask.find_by_external_id(run.id)
21
+ run.finished.wait if async == false
22
+ ForemanTasks::Task::DynflowTask.find_by_external_id!(run.id)
23
+ end
24
+
25
+ def self.async_task(action, *args, &block)
26
+ trigger_task true, action, *args, &block
27
+ end
28
+
29
+ def self.sync_task(action, *args, &block)
30
+ # TODO raise aggregation error when there are failed run-steps
31
+ trigger_task false, action, *args, &block
18
32
  end
19
33
 
20
34
  end
@@ -38,11 +38,6 @@ module ForemanTasks
38
38
  config.initialize_world.tap do |world|
39
39
  @world = world
40
40
 
41
- ActionDispatch::Reloader.to_prepare do
42
- ForemanTasks.dynflow.eager_load_actions!
43
- world.reload!
44
- end
45
-
46
41
  unless config.remote?
47
42
  at_exit { world.terminate.wait }
48
43
 
@@ -100,6 +95,7 @@ module ForemanTasks
100
95
  require_dependency file
101
96
  end
102
97
  end
98
+ @world.reload! if @world
103
99
  end
104
100
  end
105
101
  end
@@ -40,6 +40,11 @@ module ForemanTasks
40
40
  end
41
41
 
42
42
  initializer "foreman_tasks.initialize_dynflow" do
43
+ ForemanTasks.dynflow.eager_load_actions!
44
+ ActionDispatch::Reloader.to_prepare do
45
+ ForemanTasks.dynflow.eager_load_actions!
46
+ end
47
+
43
48
  unless ForemanTasks.dynflow.config.lazy_initialization
44
49
  if defined?(PhusionPassenger)
45
50
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
@@ -0,0 +1,25 @@
1
+ module ForemanTasks
2
+ module Triggers
3
+ # for test overrides if needed
4
+ attr_writer :foreman_tasks
5
+ def foreman_tasks
6
+ @foreman_tasks ||= ForemanTasks
7
+ end
8
+
9
+ def trigger(action, *args, &block)
10
+ foreman_tasks.dynflow.world.trigger action, *args, &block
11
+ end
12
+
13
+ def trigger_task(async, action, *args, &block)
14
+ foreman_tasks.trigger_task(async, action, *args, &block)
15
+ end
16
+
17
+ def async_task(action, *args, &block)
18
+ foreman_tasks.async_task(action, *args, &block)
19
+ end
20
+
21
+ def sync_task(action, *args, &block)
22
+ foreman_tasks.sync_task(action, *args, &block)
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.1.3
4
+ version: 0.1.4
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-01-29 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -132,7 +132,6 @@ files:
132
132
  - app/lib/actions/helpers/lock.rb
133
133
  - app/lib/actions/entry_action.rb
134
134
  - app/lib/actions/base.rb
135
- - app/lib/actions/test_action.rb
136
135
  - app/lib/actions/foreman/host/import_facts.rb
137
136
  - app/lib/actions/foreman/architecture/create.rb
138
137
  - app/lib/actions/foreman/architecture/update.rb
@@ -156,6 +155,7 @@ files:
156
155
  - lib/foreman_tasks/tasks/dynflow.rake
157
156
  - lib/foreman_tasks/engine.rb
158
157
  - lib/foreman_tasks/version.rb
158
+ - lib/foreman_tasks/triggers.rb
159
159
  - lib/foreman_tasks/dynflow/configuration.rb
160
160
  - lib/foreman_tasks/dynflow/persistence.rb
161
161
  - lib/foreman_tasks/dynflow/daemon.rb
@@ -1,17 +0,0 @@
1
- module Actions
2
- class TestAction < Base
3
-
4
- def run(event = nil)
5
- case event
6
- when nil
7
- suspend do |suspended_action|
8
- puts "Execution plan id is #{suspended_action.execution_plan_id}"
9
- puts "Step id is #{suspended_action.step_id}"
10
- end
11
- else
12
- puts event.inspect
13
- end
14
- end
15
-
16
- end
17
- end