foreman-tasks 0.8.6 → 0.9.0

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/.rubocop_todo.yml +138 -0
  4. data/app/controllers/foreman_tasks/api/recurring_logics_controller.rb +3 -4
  5. data/app/controllers/foreman_tasks/api/tasks_controller.rb +56 -72
  6. data/app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb +2 -4
  7. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +2 -5
  8. data/app/controllers/foreman_tasks/tasks_controller.rb +7 -8
  9. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +44 -46
  10. data/app/helpers/foreman_tasks/tasks_helper.rb +1 -1
  11. data/app/lib/actions/action_with_sub_plans.rb +6 -8
  12. data/app/lib/actions/base.rb +6 -7
  13. data/app/lib/actions/bulk_action.rb +13 -9
  14. data/app/lib/actions/entry_action.rb +1 -3
  15. data/app/lib/actions/foreman/host/import_facts.rb +2 -5
  16. data/app/lib/actions/foreman/puppetclass/import.rb +1 -1
  17. data/app/lib/actions/helpers/args_serialization.rb +0 -1
  18. data/app/lib/actions/helpers/humanizer.rb +16 -21
  19. data/app/lib/actions/helpers/with_continuous_output.rb +0 -1
  20. data/app/lib/actions/helpers/with_delegated_action.rb +2 -2
  21. data/app/lib/actions/middleware/inherit_task_groups.rb +3 -5
  22. data/app/lib/actions/middleware/keep_current_user.rb +0 -3
  23. data/app/lib/actions/middleware/recurring_logic.rb +0 -1
  24. data/app/lib/actions/proxy_action.rb +8 -8
  25. data/app/lib/actions/serializers/active_record_serializer.rb +0 -3
  26. data/app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb +3 -3
  27. data/app/models/foreman_tasks/concerns/action_subject.rb +4 -6
  28. data/app/models/foreman_tasks/concerns/action_triggering.rb +20 -33
  29. data/app/models/foreman_tasks/concerns/host_action_subject.rb +5 -5
  30. data/app/models/foreman_tasks/lock.rb +29 -37
  31. data/app/models/foreman_tasks/recurring_logic.rb +23 -24
  32. data/app/models/foreman_tasks/task.rb +65 -39
  33. data/app/models/foreman_tasks/task/dynflow_task.rb +23 -24
  34. data/app/models/foreman_tasks/task/status_explicator.rb +3 -3
  35. data/app/models/foreman_tasks/task/summarizer.rb +3 -3
  36. data/app/models/foreman_tasks/task_group.rb +0 -2
  37. data/app/models/foreman_tasks/task_group_member.rb +0 -2
  38. data/app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb +1 -4
  39. data/app/models/foreman_tasks/triggering.rb +19 -19
  40. data/app/models/setting/foreman_tasks.rb +8 -11
  41. data/app/services/foreman_tasks/proxy_selector.rb +4 -5
  42. data/app/views/foreman_tasks/tasks/_details.html.erb +1 -1
  43. data/bin/dynflow-executor +1 -1
  44. data/bin/foreman-tasks +1 -1
  45. data/config/routes.rb +1 -1
  46. data/db/migrate/20150814204140_add_task_type_value_index.rb +1 -1
  47. data/db/migrate/20160924213030_change_tasks_widget_names.rb +8 -8
  48. data/db/seeds.d/61-foreman_tasks_bookmarks.rb +3 -3
  49. data/deploy/foreman-tasks.sysconfig +6 -0
  50. data/extra/dynflow-debug.sh +12 -0
  51. data/foreman-tasks.gemspec +1 -1
  52. data/lib/foreman_tasks.rb +3 -3
  53. data/lib/foreman_tasks/authorizer_ext.rb +1 -1
  54. data/lib/foreman_tasks/cleaner.rb +14 -16
  55. data/lib/foreman_tasks/dynflow.rb +11 -9
  56. data/lib/foreman_tasks/dynflow/configuration.rb +8 -10
  57. data/lib/foreman_tasks/dynflow/console_authorizer.rb +4 -5
  58. data/lib/foreman_tasks/dynflow/daemon.rb +17 -19
  59. data/lib/foreman_tasks/dynflow/persistence.rb +5 -8
  60. data/lib/foreman_tasks/engine.rb +30 -31
  61. data/lib/foreman_tasks/task_error.rb +1 -3
  62. data/lib/foreman_tasks/tasks/cleanup.rake +7 -19
  63. data/lib/foreman_tasks/tasks/dynflow.rake +1 -1
  64. data/lib/foreman_tasks/tasks/export_tasks.rake +51 -59
  65. data/lib/foreman_tasks/test_extensions.rb +1 -1
  66. data/lib/foreman_tasks/version.rb +1 -1
  67. data/lib/tasks/gettext.rake +10 -7
  68. data/locale/action_names.rb +3 -6
  69. data/locale/en/foreman_tasks.po +189 -177
  70. data/locale/foreman_tasks.pot +177 -137
  71. data/test/controllers/api/recurring_logics_controller_test.rb +3 -5
  72. data/test/controllers/api/tasks_controller_test.rb +5 -7
  73. data/test/factories/task_factory.rb +8 -8
  74. data/test/factories/triggering_factory.rb +2 -3
  75. data/test/helpers/foreman_tasks/tasks_helper_test.rb +11 -11
  76. data/test/support/dummy_proxy_action.rb +3 -4
  77. data/test/unit/actions/action_with_sub_plans_test.rb +5 -6
  78. data/test/unit/actions/proxy_action_test.rb +5 -8
  79. data/test/unit/cleaner_test.rb +11 -12
  80. data/test/unit/dynflow_console_authorizer_test.rb +4 -4
  81. data/test/unit/proxy_selector_test.rb +3 -3
  82. data/test/unit/recurring_logic_test.rb +19 -17
  83. data/test/unit/task_groups_test.rb +3 -4
  84. data/test/unit/task_test.rb +72 -5
  85. data/test/unit/triggering_test.rb +0 -1
  86. metadata +7 -6
  87. data/app/controllers/foreman_tasks/concerns/environments_extension.rb +0 -24
data/lib/foreman_tasks.rb CHANGED
@@ -22,10 +22,10 @@ module ForemanTasks
22
22
  Match! async, true, false
23
23
 
24
24
  match trigger(action, *args, &block),
25
- (on ::Dynflow::World::PlaningFailed.(error: ~any) do |error|
25
+ (on ::Dynflow::World::PlaningFailed.call(error: ~any) do |error|
26
26
  raise error
27
27
  end),
28
- (on ::Dynflow::World::Triggered.(execution_plan_id: ~any, future: ~any) do |id, finished|
28
+ (on ::Dynflow::World::Triggered.call(execution_plan_id: ~any, future: ~any) do |id, finished|
29
29
  finished.wait if async == false
30
30
  ForemanTasks::Task::DynflowTask.where(:external_id => id).first!
31
31
  end)
@@ -37,7 +37,7 @@ module ForemanTasks
37
37
 
38
38
  def self.sync_task(action, *args, &block)
39
39
  trigger_task(false, action, *args, &block).tap do |task|
40
- raise TaskError.new(task) if task.execution_plan.error? || task.execution_plan.result == :warning
40
+ raise TaskError, task if task.execution_plan.error? || task.execution_plan.result == :warning
41
41
  end
42
42
  end
43
43
 
@@ -10,7 +10,7 @@ module ForemanTasks
10
10
 
11
11
  def resource_name_with_authorized_resource_name(klass)
12
12
  if klass.respond_to?(:authorized_resource_name)
13
- return klass.authorized_resource_name
13
+ klass.authorized_resource_name
14
14
  else
15
15
  resource_name_without_authorized_resource_name(klass)
16
16
  end
@@ -1,10 +1,9 @@
1
1
  module ForemanTasks
2
2
  # Represents the cleanup mechanism for tasks
3
3
  class Cleaner
4
-
5
4
  def self.run(options)
6
5
  if options.key?(:filter)
7
- self.new(options).delete
6
+ new(options).delete
8
7
  else
9
8
  [:after, :states].each do |invalid_option|
10
9
  if options.key?(invalid_option)
@@ -12,10 +11,10 @@ module ForemanTasks
12
11
  end
13
12
  end
14
13
  if cleanup_settings[:after]
15
- self.new(options.merge(:filter => "", :after => cleanup_settings[:after])).delete
14
+ new(options.merge(:filter => '', :after => cleanup_settings[:after])).delete
16
15
  end
17
16
  actions_with_default_cleanup.each do |action_class, period|
18
- self.new(options.merge(:filter => "label = #{action_class.name}", :after => period)).delete
17
+ new(options.merge(:filter => "label = #{action_class.name}", :after => period)).delete
19
18
  end
20
19
  end
21
20
  end
@@ -37,7 +36,7 @@ module ForemanTasks
37
36
  actions_with_periods[action_class] = action_class.cleanup_after
38
37
  end
39
38
  end
40
- return actions_with_periods
39
+ actions_with_periods
41
40
  end
42
41
 
43
42
  def self.cleanup_settings
@@ -45,7 +44,7 @@ module ForemanTasks
45
44
  @cleanup_settings = SETTINGS[:'foreman-tasks'] && SETTINGS[:'foreman-tasks'][:cleanup] || {}
46
45
  end
47
46
 
48
- attr_reader :filter, :after , :states, :verbose, :batch_size, :noop, :full_filter
47
+ attr_reader :filter, :after, :states, :verbose, :batch_size, :noop, :full_filter
49
48
 
50
49
  # @param filter [String] scoped search matching the tasks to be deleted
51
50
  # @param after [String|nil] delete the tasks after they are older
@@ -57,7 +56,7 @@ module ForemanTasks
57
56
  :verbose => false,
58
57
  :batch_size => 1000,
59
58
  :noop => false,
60
- :states => ["stopped"] }
59
+ :states => ['stopped'] }
61
60
  options = default_options.merge(options)
62
61
 
63
62
  @filter = options[:filter]
@@ -69,7 +68,7 @@ module ForemanTasks
69
68
 
70
69
  raise ArgumentError, 'filter not speficied' if @filter.nil?
71
70
 
72
- @full_filter = prepare_filter
71
+ @full_filter = prepare_filter
73
72
  end
74
73
 
75
74
  # Delete the filtered tasks, including the dynflow execution plans
@@ -102,14 +101,15 @@ module ForemanTasks
102
101
 
103
102
  def prepare_filter
104
103
  filter_parts = [filter]
105
- filter_parts << %{started_at < "#{after.ago.to_s(:db)}"} if after > 0
106
- filter_parts << states.map { |s| "state = #{s}" }.join(" OR ") if states.any?
104
+ filter_parts << %(started_at < "#{after.ago.to_s(:db)}") if after > 0
105
+ filter_parts << states.map { |s| "state = #{s}" }.join(' OR ') if states.any?
107
106
  filter_parts.select(&:present?).join(' AND ')
108
107
  end
109
108
 
110
109
  def start_tracking_progress
111
110
  if verbose
112
- @current, @total = 0, tasks.size
111
+ @current = 0
112
+ @total = tasks.size
113
113
  say "#{@current}/#{@total}", false
114
114
  end
115
115
  end
@@ -123,13 +123,11 @@ module ForemanTasks
123
123
 
124
124
  def say(message, log = true)
125
125
  puts message
126
- if log
127
- Foreman::Logging.logger('foreman-tasks').info(message)
128
- end
126
+ Foreman::Logging.logger('foreman-tasks').info(message) if log
129
127
  end
130
128
 
131
129
  def parse_time_interval(string)
132
- matched_string = string.gsub(' ','').match(/\A(\d+)(\w)\Z/)
130
+ matched_string = string.delete(' ').match(/\A(\d+)(\w)\Z/)
133
131
  unless matched_string
134
132
  raise ArgumentError, "String #{string} isn't an expected specification of time in format of \"{number}{time_unit}\""
135
133
  end
@@ -146,7 +144,7 @@ module ForemanTasks
146
144
  else
147
145
  raise ArgumentError, "Unexpected time unit in #{string}, expected one of [s,h,d,y]"
148
146
  end
149
- return value
147
+ value
150
148
  end
151
149
  end
152
150
  end
@@ -35,14 +35,18 @@ module ForemanTasks
35
35
  return @world if @world
36
36
 
37
37
  if config.lazy_initialization && defined?(PhusionPassenger)
38
- config.dynflow_logger.warn("ForemanTasks: lazy loading with PhusionPassenger might lead to unexpected results")
38
+ config.dynflow_logger.warn('ForemanTasks: lazy loading with PhusionPassenger might lead to unexpected results')
39
39
  end
40
40
  config.initialize_world.tap do |world|
41
41
  @world = world
42
42
 
43
43
  unless config.remote?
44
44
  # don't try to do any rescuing until the tables are properly migrated
45
- if !Foreman.in_rake?('db:migrate') && (ForemanTasks::Task.table_exists? rescue(false))
45
+ if !Foreman.in_rake?('db:migrate') && (begin
46
+ ForemanTasks::Task.table_exists?
47
+ rescue
48
+ (false)
49
+ end)
46
50
  config.run_on_init_hooks(world)
47
51
  # leave this just for long-running executors
48
52
  unless config.rake_task_with_executor?
@@ -66,7 +70,7 @@ module ForemanTasks
66
70
 
67
71
  def reinitialize!
68
72
  @world = nil
69
- self.initialize!
73
+ initialize!
70
74
  end
71
75
 
72
76
  def world
@@ -79,24 +83,22 @@ module ForemanTasks
79
83
  'in some initializer'
80
84
  end
81
85
 
82
- return @world
86
+ @world
83
87
  end
84
88
 
85
- def world=(world)
86
- @world = world
87
- end
89
+ attr_writer :world
88
90
 
89
91
  def web_console
90
92
  ::Dynflow::Web.setup do
91
93
  before do
92
94
  if !Setting[:dynflow_enable_console] ||
93
- (Setting[:dynflow_console_require_auth] && !ConsoleAuthorizer.new(env).allow?)
95
+ (Setting[:dynflow_console_require_auth] && !ConsoleAuthorizer.new(env).allow?)
94
96
  halt 403, 'Access forbidden'
95
97
  end
96
98
  end
97
99
 
98
100
  set(:custom_navigation) do
99
- { _("Back to tasks") => "/#{ForemanTasks::TasksController.controller_path}" }
101
+ { _('Back to tasks') => "/#{ForemanTasks::TasksController.controller_path}" }
100
102
  end
101
103
  set(:world) { ForemanTasks.dynflow.world }
102
104
  end
@@ -1,6 +1,5 @@
1
1
  module ForemanTasks
2
2
  class Dynflow::Configuration
3
-
4
3
  # the number of threads in the pool handling the execution
5
4
  attr_accessor :pool_size
6
5
 
@@ -9,7 +8,7 @@ module ForemanTasks
9
8
 
10
9
  # set true if the executor runs externally (by default true in procution, othewise false)
11
10
  attr_accessor :remote
12
- alias_method :remote?, :remote
11
+ alias remote? remote
13
12
 
14
13
  # what transaction adapater should be used, by default, it uses the ActiveRecord
15
14
  # based adapter, expecting ActiveRecord is used as ORM in the application
@@ -34,7 +33,7 @@ module ForemanTasks
34
33
  self.transaction_adapter = ::Dynflow::TransactionAdapters::ActiveRecord.new
35
34
  self.eager_load_paths = []
36
35
  self.lazy_initialization = !Rails.env.production?
37
- self.rake_tasks_with_executor = %w[db:migrate db:seed]
36
+ self.rake_tasks_with_executor = %w(db:migrate db:seed)
38
37
 
39
38
  @on_init = []
40
39
  end
@@ -66,8 +65,8 @@ module ForemanTasks
66
65
  # it can't be remote
67
66
  def remote?
68
67
  !ForemanTasks.dynflow.executor? &&
69
- !rake_task_with_executor? &&
70
- @remote
68
+ !rake_task_with_executor? &&
69
+ @remote
71
70
  end
72
71
 
73
72
  def rake_task_with_executor?
@@ -79,7 +78,7 @@ module ForemanTasks
79
78
  end
80
79
 
81
80
  def increase_db_pool_size?
82
- ForemanTasks.dynflow.required? && !remote? && !Rails.env.test?
81
+ ForemanTasks.dynflow.required? && !remote? && !Rails.env.test?
83
82
  end
84
83
 
85
84
  # To avoid pottential timeouts on db connection pool, make sure
@@ -126,14 +125,14 @@ module ForemanTasks
126
125
  db_config['database'] = "#{File.dirname(database)}/dynflow-#{File.basename(database)}"
127
126
  end
128
127
  end
129
- return db_config
128
+ db_config
130
129
  end
131
130
 
132
131
  def initialize_executor(world)
133
- if self.remote?
132
+ if remote?
134
133
  false
135
134
  else
136
- ::Dynflow::Executors::Parallel.new(world, self.pool_size)
135
+ ::Dynflow::Executors::Parallel.new(world, pool_size)
137
136
  end
138
137
  end
139
138
 
@@ -145,6 +144,5 @@ module ForemanTasks
145
144
  def initialize_persistence
146
145
  ForemanTasks::Dynflow::Persistence.new(default_sequel_adapter_options)
147
146
  end
148
-
149
147
  end
150
148
  end
@@ -21,7 +21,7 @@ module ForemanTasks
21
21
  def unlimited_edit?
22
22
  return true if @user.admin?
23
23
  # users with unlimited edit_foreman_tasks can operate with the
24
- # console no matter what task it is
24
+ # console no matter what task it is...
25
25
  edit_permission = Permission.where(:name => :edit_foreman_tasks, :resource_type => ForemanTasks::Task.name).first
26
26
  if @user.filters.joins(:filterings).unlimited.where('filterings.permission_id' => edit_permission).first
27
27
  return true
@@ -29,7 +29,7 @@ module ForemanTasks
29
29
  end
30
30
 
31
31
  def authorized_for_task?
32
- if task = extract_task
32
+ if (task = extract_task)
33
33
  begin
34
34
  original_user = User.current
35
35
  User.current = @user
@@ -38,16 +38,15 @@ module ForemanTasks
38
38
  User.current = original_user
39
39
  end
40
40
  else
41
- return false
41
+ false
42
42
  end
43
43
  end
44
44
 
45
45
  def extract_task
46
- dynflow_id = @rack_request.path_info[/^\/([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})/,1]
46
+ dynflow_id = @rack_request.path_info[/^\/([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})/, 1]
47
47
  unless dynflow_id.empty?
48
48
  ForemanTasks::Task::DynflowTask.where(:external_id => dynflow_id).first
49
49
  end
50
50
  end
51
-
52
51
  end
53
52
  end
@@ -2,25 +2,24 @@ require 'fileutils'
2
2
 
3
3
  module ForemanTasks
4
4
  class Dynflow::Daemon
5
-
6
5
  # load the Rails environment and initialize the executor
7
6
  # in this thread.
8
7
  def run(foreman_root = Dir.pwd)
9
- STDERR.puts("Starting Rails environment")
10
- foreman_env_file = File.expand_path("./config/environment.rb", foreman_root)
11
- unless File.exists?(foreman_env_file)
8
+ STDERR.puts('Starting Rails environment')
9
+ foreman_env_file = File.expand_path('./config/environment.rb', foreman_root)
10
+ unless File.exist?(foreman_env_file)
12
11
  raise "#{foreman_root} doesn't seem to be a foreman root directory"
13
12
  end
14
13
  ForemanTasks.dynflow.executor!
15
14
  require foreman_env_file
16
- STDERR.puts("Everything ready")
15
+ STDERR.puts('Everything ready')
17
16
  sleep
18
17
  ensure
19
- STDERR.puts("Exiting")
18
+ STDERR.puts('Exiting')
20
19
  end
21
20
 
22
21
  # run the executor as a daemon
23
- def run_background(command = "start", options = {})
22
+ def run_background(command = 'start', options = {})
24
23
  default_options = { foreman_root: Dir.pwd,
25
24
  process_name: 'dynflow_executor',
26
25
  pid_dir: "#{Rails.root}/tmp/pids",
@@ -36,7 +35,7 @@ module ForemanTasks
36
35
  raise "You need to add gem 'daemons' to your Gemfile if you wish to use it."
37
36
  end
38
37
 
39
- unless %w[start stop restart run].include?(command)
38
+ unless %w(start stop restart run).include?(command)
40
39
  raise "Command exptected to be 'start', 'stop', 'restart', 'run', was #{command.inspect}"
41
40
  end
42
41
 
@@ -44,19 +43,20 @@ module ForemanTasks
44
43
 
45
44
  options[:executors_count].times do
46
45
  Daemons.run_proc(options[:process_name],
47
- :multiple => true,
48
- :dir => options[:pid_dir],
49
- :log_dir => options[:log_dir],
50
- :dir_mode => :normal,
51
- :monitor => true,
52
- :log_output => true,
53
- :ARGV => [command]) do |*args|
46
+ :multiple => true,
47
+ :dir => options[:pid_dir],
48
+ :log_dir => options[:log_dir],
49
+ :dir_mode => :normal,
50
+ :monitor => true,
51
+ :log_output => true,
52
+ :log_output_syslog => true,
53
+ :ARGV => [command]) do |*_args|
54
54
  begin
55
55
  ::Logging.reopen
56
56
  run(options[:foreman_root])
57
57
  rescue => e
58
58
  STDERR.puts e.message
59
- Foreman::Logging.exception("Failed running foreman-tasks daemon", e)
59
+ Foreman::Logging.exception('Failed running foreman-tasks daemon', e)
60
60
  exit 1
61
61
  end
62
62
  end
@@ -66,9 +66,7 @@ module ForemanTasks
66
66
  protected
67
67
 
68
68
  def world
69
- ForemanTasks.dynflow.world
69
+ ForemanTasks.dynflow.world
70
70
  end
71
-
72
-
73
71
  end
74
72
  end
@@ -1,19 +1,17 @@
1
1
  module ForemanTasks
2
-
3
2
  # wrap the dynflow persistence to reflect the changes to execution plan
4
3
  # in the Task model. This is probably a temporary solution and
5
4
  # Dynflow will probably get more events-based API but it should be enought
6
5
  # for start, until the requiements on the API are clear enough.
7
6
  class Dynflow::Persistence < ::Dynflow::PersistenceAdapters::Sequel
8
-
9
7
  def save_execution_plan(execution_plan_id, value)
10
8
  # clear connection only if not running in some active record transaction already
11
- clear_connections = ActiveRecord::Base.connection.open_transactions == 0
9
+ clear_connections = ActiveRecord::Base.connection.open_transactions.zero?
12
10
  super.tap do
13
11
  begin
14
12
  on_execution_plan_save(execution_plan_id, value)
15
13
  rescue => e
16
- Foreman::Logging.exception("Error on on_execution_plan_save event", e, :logger => 'foreman-tasks/dynflow')
14
+ Foreman::Logging.exception('Error on on_execution_plan_save event', e, :logger => 'foreman-tasks/dynflow')
17
15
  end
18
16
  end
19
17
  ensure
@@ -26,11 +24,11 @@ module ForemanTasks
26
24
  case data[:state]
27
25
  when :pending
28
26
  task = ForemanTasks::Task::DynflowTask.new_for_execution_plan(execution_plan_id, data)
29
- task.start_at ||= Time.now
27
+ task.start_at ||= Time.zone.now
30
28
  task.save!
31
29
  when :scheduled
32
30
  delayed_plan = load_delayed_plan(execution_plan_id)
33
- raise Foreman::Exception.new('Plan is delayed but the delay record is missing') if delayed_plan.nil?
31
+ raise Foreman::Exception, 'Plan is delayed but the delay record is missing' if delayed_plan.nil?
34
32
  task = ::ForemanTasks::Task::DynflowTask.find_by!(:external_id => execution_plan_id)
35
33
  task.update_from_dynflow(data.merge(:start_at => delayed_plan[:start_at],
36
34
  :start_before => delayed_plan[:start_before]))
@@ -39,13 +37,12 @@ module ForemanTasks
39
37
  task.update_from_dynflow(data)
40
38
  Lock.owner!(::User.current, task.id) if ::User.current
41
39
  else
42
- if task = ::ForemanTasks::Task::DynflowTask.where(:external_id => execution_plan_id).first
40
+ if (task = ::ForemanTasks::Task::DynflowTask.where(:external_id => execution_plan_id).first)
43
41
  unless task.state.to_s == data[:state].to_s
44
42
  task.update_from_dynflow(data)
45
43
  end
46
44
  end
47
45
  end
48
46
  end
49
-
50
47
  end
51
48
  end
@@ -4,10 +4,14 @@ require 'gettext_i18n_rails'
4
4
 
5
5
  module ForemanTasks
6
6
  class Engine < ::Rails::Engine
7
- engine_name "foreman_tasks"
7
+ engine_name 'foreman_tasks'
8
8
 
9
9
  initializer 'foreman_tasks.load_default_settings', :before => :load_config_initializers do
10
- require_dependency File.expand_path('../../../app/models/setting/foreman_tasks.rb', __FILE__) if (Setting.table_exists? rescue(false))
10
+ require_dependency File.expand_path('../../../app/models/setting/foreman_tasks.rb', __FILE__) if begin
11
+ Setting.table_exists?
12
+ rescue
13
+ (false)
14
+ end
11
15
  end
12
16
 
13
17
  # Precompile any JS or CSS files under app/assets/
@@ -35,9 +39,9 @@ module ForemanTasks
35
39
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
36
40
  end
37
41
 
38
- initializer 'foreman_tasks.register_plugin', :before => :finisher_hook do |app|
42
+ initializer 'foreman_tasks.register_plugin', :before => :finisher_hook do |_app|
39
43
  Foreman::Plugin.register :"foreman-tasks" do
40
- requires_foreman '>= 1.9.0'
44
+ requires_foreman '>= 1.15.0'
41
45
  divider :top_menu, :parent => :monitor_menu, :last => true
42
46
  menu :top_menu, :tasks,
43
47
  :url_hash => { :controller => 'foreman_tasks/tasks', :action => :index },
@@ -51,64 +55,63 @@ module ForemanTasks
51
55
  :parent => :monitor_menu,
52
56
  :last => true
53
57
 
54
- security_block :foreman_tasks do |map|
55
- permission :view_foreman_tasks, {:'foreman_tasks/tasks' => [:auto_complete_search, :sub_tasks, :index, :show],
56
- :'foreman_tasks/api/tasks' => [:bulk_search, :show, :index, :summary] }, :resource_type => ForemanTasks::Task.name
57
- permission :edit_foreman_tasks, {:'foreman_tasks/tasks' => [:resume, :unlock, :force_unlock, :cancel_step, :cancel],
58
- :'foreman_tasks/api/tasks' => [:bulk_resume]}, :resource_type => ForemanTasks::Task.name
58
+ security_block :foreman_tasks do |_map|
59
+ permission :view_foreman_tasks, { :'foreman_tasks/tasks' => [:auto_complete_search, :sub_tasks, :index, :show],
60
+ :'foreman_tasks/api/tasks' => [:bulk_search, :show, :index, :summary] }, :resource_type => ForemanTasks::Task.name
61
+ permission :edit_foreman_tasks, { :'foreman_tasks/tasks' => [:resume, :unlock, :force_unlock, :cancel_step, :cancel],
62
+ :'foreman_tasks/api/tasks' => [:bulk_resume] }, :resource_type => ForemanTasks::Task.name
59
63
 
60
- permission :create_recurring_logics, { }, :resource_type => ForemanTasks::RecurringLogic.name
64
+ permission :create_recurring_logics, {}, :resource_type => ForemanTasks::RecurringLogic.name
61
65
 
62
66
  permission :view_recurring_logics, { :'foreman_tasks/recurring_logics' => [:index, :show],
63
67
  :'foreman_tasks/api/recurring_logics' => [:index, :show] }, :resource_type => ForemanTasks::RecurringLogic.name
64
68
 
65
69
  permission :edit_recurring_logics, { :'foreman_tasks/recurring_logics' => [:cancel],
66
70
  :'foreman_tasks/api/recurring_logics' => [:cancel] }, :resource_type => ForemanTasks::RecurringLogic.name
67
-
68
71
  end
69
72
 
70
73
  logger :dynflow, :enabled => true
71
74
  logger :action, :enabled => true
72
75
 
73
- role "Tasks Manager", [:view_foreman_tasks, :edit_foreman_tasks]
74
- role "Tasks Reader", [:view_foreman_tasks]
76
+ role 'Tasks Manager', [:view_foreman_tasks, :edit_foreman_tasks]
77
+ role 'Tasks Reader', [:view_foreman_tasks]
75
78
 
76
- widget 'foreman_tasks/tasks/dashboard/tasks_status', :sizex=>6, :sizey=>1, :name=> N_('Task Status')
77
- widget 'foreman_tasks/tasks/dashboard/latest_tasks_in_error_warning', :sizex=>6, :sizey=>1,:name=> N_('Latest Warning/Error Tasks')
79
+ widget 'foreman_tasks/tasks/dashboard/tasks_status', :sizex => 6, :sizey => 1, :name => N_('Task Status')
80
+ widget 'foreman_tasks/tasks/dashboard/latest_tasks_in_error_warning', :sizex => 6, :sizey => 1, :name => N_('Latest Warning/Error Tasks')
78
81
  end
79
82
  end
80
83
 
81
- initializer 'foreman_tasks.ignore_dynflow_tables' do |app|
84
+ initializer 'foreman_tasks.ignore_dynflow_tables' do |_app|
82
85
  # Ignore Dynflow tables when schema-dumping. Dynflow tables are handled automatically by Dynflow.
83
86
  ActiveRecord::SchemaDumper.ignore_tables << /^dynflow_.*$/
84
87
  end
85
88
 
86
- initializer "foreman_tasks.apipie" do
89
+ initializer 'foreman_tasks.apipie' do
87
90
  # this condition is here for compatibility reason to work with Foreman 1.4.x
88
91
  if Apipie.configuration.api_controllers_matcher.is_a?(Array) &&
89
- Apipie.configuration.respond_to?(:checksum_path)
92
+ Apipie.configuration.respond_to?(:checksum_path)
90
93
  Apipie.configuration.api_controllers_matcher << "#{ForemanTasks::Engine.root}/app/controllers/foreman_tasks/api/*.rb"
91
94
  Apipie.configuration.checksum_path += ['/foreman_tasks/api/']
92
95
  end
93
96
  end
94
97
 
95
- initializer "foreman_tasks.register_paths" do |app|
96
- ForemanTasks.dynflow.config.eager_load_paths.concat(%W[#{ForemanTasks::Engine.root}/app/lib/actions])
98
+ initializer 'foreman_tasks.register_paths' do |_app|
99
+ ForemanTasks.dynflow.config.eager_load_paths.concat(%W(#{ForemanTasks::Engine.root}/app/lib/actions))
97
100
  end
98
101
 
99
- initializer "foreman_tasks.test_exceptions" do |app|
102
+ initializer 'foreman_tasks.test_exceptions' do |_app|
100
103
  if defined? ActiveSupport::TestCase
101
104
  require 'foreman_tasks/test_extensions'
102
105
  end
103
106
  end
104
107
 
105
- initializer "foreman_tasks.load_app_instance_data" do |app|
108
+ initializer 'foreman_tasks.load_app_instance_data' do |app|
106
109
  ForemanTasks::Engine.paths['db/migrate'].existent.each do |path|
107
110
  app.config.paths['db/migrate'] << path
108
111
  end
109
112
  end
110
113
 
111
- initializer "foreman_tasks.require_dynflow", :before => "foreman_tasks.initialize_dynflow" do |app|
114
+ initializer 'foreman_tasks.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app|
112
115
  ForemanTasks.dynflow.require!
113
116
  ::ForemanTasks.dynflow.config.on_init do |world|
114
117
  ForemanTasksCore.dynflow_setup(world)
@@ -128,8 +131,6 @@ module ForemanTasks
128
131
  if ENV['FOREMAN_TASKS_MONKEYS'] == 'true'
129
132
  config.to_prepare do
130
133
  ::Api::V2::HostsController.send :include, ForemanTasks::Concerns::HostsControllerExtension
131
- ::PuppetclassesController.send :include, ForemanTasks::Concerns::EnvironmentsExtension
132
- ::EnvironmentsController.send :include, ForemanTasks::Concerns::EnvironmentsExtension
133
134
  ::Host::Base.send :include, ForemanTasks::Concerns::HostActionSubject
134
135
  end
135
136
  end
@@ -147,9 +148,7 @@ module ForemanTasks
147
148
  unless ForemanTasks.dynflow.config.lazy_initialization
148
149
  if defined?(PhusionPassenger)
149
150
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
150
- if forked
151
- ForemanTasks.dynflow.initialize!
152
- end
151
+ ForemanTasks.dynflow.initialize! if forked
153
152
  end
154
153
  else
155
154
  ForemanTasks.dynflow.initialize!
@@ -158,15 +157,15 @@ module ForemanTasks
158
157
  end
159
158
 
160
159
  rake_tasks do
161
- %w[dynflow.rake test.rake export_tasks.rake cleanup.rake].each do |rake_file|
160
+ %w(dynflow.rake test.rake export_tasks.rake cleanup.rake).each do |rake_file|
162
161
  full_path = File.expand_path("../tasks/#{rake_file}", __FILE__)
163
- load full_path if File.exists?(full_path)
162
+ load full_path if File.exist?(full_path)
164
163
  end
165
164
  end
166
165
  end
167
166
 
168
167
  def self.table_name_prefix
169
- "foreman_tasks_"
168
+ 'foreman_tasks_'
170
169
  end
171
170
 
172
171
  def use_relative_model_naming