foreman-tasks 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,6 +52,9 @@ module ForemanTasks
52
52
  param :resource_type, String, :desc => <<-DESC
53
53
  In case :type = 'resource', what resource id we're searching the tasks for
54
54
  DESC
55
+ param :action_types, [String], :desc => <<-DESC
56
+ Return just tasks of given action type, e.g. ["Actions::Katello::Repository::Synchronize"]
57
+ DESC
55
58
  param :active_only, :bool
56
59
  param :page, String
57
60
  param :per_page, String
@@ -80,6 +83,7 @@ module ForemanTasks
80
83
  scope = ordering_scope(scope, search_params)
81
84
  scope = search_scope(scope, search_params)
82
85
  scope = active_scope(scope, search_params)
86
+ scope = action_types_scope(scope, search_params)
83
87
  scope = pagination_scope(scope, search_params)
84
88
  scope.all.map { |task| task_hash(task) }
85
89
  end
@@ -122,6 +126,14 @@ module ForemanTasks
122
126
  end
123
127
  end
124
128
 
129
+ def action_types_scope(scope, search_params)
130
+ if action_types = search_params[:action_types]
131
+ scope.for_action_types(action_types)
132
+ else
133
+ scope
134
+ end
135
+ end
136
+
125
137
  def pagination_scope(scope, search_params)
126
138
  page = search_params[:page] || 1
127
139
  per_page = search_params[:per_page] || 10
@@ -20,7 +20,7 @@ module Actions
20
20
  self.class.name.demodulize.underscore.humanize
21
21
  end
22
22
 
23
- # This method should return String of Array<String> describing input for the task
23
+ # This method should return String or Array<String> describing input for the task
24
24
  def humanized_input
25
25
  if task_input.blank?
26
26
  ""
@@ -40,10 +40,11 @@ module Actions
40
40
  end
41
41
  end
42
42
 
43
- def humanized_error
43
+ # This method should return String or Array<String> describing the errors during the action
44
+ def humanized_errors
44
45
  execution_plan.steps_in_state(:skipped, :skipping, :error).map do |step|
45
- step.error.message
46
- end.join("\n")
46
+ step.error.message if step.error
47
+ end.compact
47
48
  end
48
49
  end
49
50
  end
@@ -13,13 +13,14 @@ module ForemanTasks
13
13
  class LockConflict < StandardError
14
14
  attr_reader :required_lock, :conflicting_locks
15
15
  def initialize(required_lock, conflicting_locks)
16
- header = <<-TXT.gsub(/^ *\|/, '')
17
- |Required lock is already taken by other running tasks.
18
- |Please inspect their state, fix their errors nad resume them.
19
- |
20
- |Required lock: #{required_lock.name}
21
- |Conflicts with tasks:
22
- TXT
16
+ header = _("Required lock is already taken by other running tasks.")
17
+ header << "\n"
18
+ header << _("Please inspect their state, fix their errors and resume them.")
19
+ header << "\n\n"
20
+ header << _("Required lock: %s") % required_lock.name
21
+ header << "\n"
22
+ header << _("Conflicts with tasks:")
23
+ header << "\n"
23
24
  url_helpers = Rails.application.routes.url_helpers
24
25
  conflicting_tasks = conflicting_locks.
25
26
  map(&:task).
@@ -30,6 +30,7 @@ module ForemanTasks
30
30
  joins(:locks).where(:"foreman_tasks_locks.resource_id" => resource.id,
31
31
  :"foreman_tasks_locks.resource_type" => resource.class.name)
32
32
  end)
33
+ scope :for_action_types, (lambda { |action_types| where('label IN (?)', Array(action_types)) })
33
34
 
34
35
  def input
35
36
  {}
@@ -5,21 +5,13 @@ module ForemanTasks
5
5
 
6
6
  scope :for_action, ->(action_class) { where(label: action_class.name) }
7
7
 
8
- def update_from_dynflow(data, planned)
8
+ def update_from_dynflow(data)
9
9
  self.external_id = data[:id]
10
10
  self.started_at = data[:started_at]
11
11
  self.ended_at = data[:ended_at]
12
12
  self.state = data[:state].to_s
13
13
  self.result = data[:result].to_s
14
-
15
- if planned
16
- # for now, this part needs to laod the execution_plan to
17
- # load extra data, there is place for optimization on Dynflow side
18
- # if needed (getting more keys into the data value)
19
- unless self.label
20
- self.label = main_action.class.name
21
- end
22
- end
14
+ self.label ||= main_action.class.name
23
15
  self.save!
24
16
  end
25
17
 
@@ -58,7 +50,8 @@ module ForemanTasks
58
50
  def humanized
59
51
  { action: get_humanized(:humanized_name),
60
52
  input: get_humanized(:humanized_input),
61
- output: [get_humanized(:humanized_output), get_humanized(:humanized_error)].reject(&:blank?).join("\n") }
53
+ output: get_humanized(:humanized_output),
54
+ errors: get_humanized(:humanized_errors) }
62
55
  end
63
56
 
64
57
  def cli_example
@@ -73,7 +66,7 @@ module ForemanTasks
73
66
  end
74
67
 
75
68
  def get_humanized(method)
76
- Match! method, :humanized_name, :humanized_input, :humanized_output, :humanized_error
69
+ Match! method, :humanized_name, :humanized_input, :humanized_output, :humanized_errors
77
70
  if main_action.respond_to? method
78
71
  begin
79
72
  main_action.send method
@@ -2,7 +2,7 @@
2
2
  <%= link_to(_('Auto Reload'), '', class: %w(btn btn-sm btn-default reload-button hidden)) %>
3
3
 
4
4
  <%= link_to(_('Dynflow console'),
5
- format('/foreman_tasks/dynflow/%s', @task.external_id),
5
+ format((defined?(Rails) ? request.script_name : '') + '/foreman_tasks/dynflow/%s', @task.external_id),
6
6
  class: %w(btn btn-sm btn-default)) if Setting['dynflow_enable_console'] %>
7
7
 
8
8
  <%= link_to(_('Resume'),
@@ -21,14 +21,14 @@ module ForemanTasks
21
21
  def on_execution_plan_save(execution_plan_id, data)
22
22
  # We can load the data unless the execution plan was properly planned and saved
23
23
  # including its steps
24
- if data[:state] == :pending
24
+ if data[:state] == :planning
25
25
  task = ::ForemanTasks::Task::DynflowTask.new
26
- task.update_from_dynflow(data, false)
26
+ task.update_from_dynflow(data)
27
27
  Lock.owner!(::User.current, task.id) if ::User.current
28
- elsif data[:state] != :planning
28
+ elsif data[:state] != :pending
29
29
  if task = ::ForemanTasks::Task::DynflowTask.find_by_external_id(execution_plan_id)
30
30
  unless task.state.to_s == data[:state].to_s
31
- task.update_from_dynflow(data, true)
31
+ task.update_from_dynflow(data)
32
32
  end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
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.6.4
4
+ version: 0.6.5
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-06-20 00:00:00.000000000 Z
12
+ date: 2014-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.7.0
53
+ version: 0.7.2
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.7.0
61
+ version: 0.7.2
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: sequel
64
64
  requirement: !ruby/object:Gem::Requirement