foreman-tasks 0.7.20 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d050fd7d55d78ed330c5da74b31f7a340f652d85
4
- data.tar.gz: 35e4c705611f00c5323dcdcca943d41a71dc988a
3
+ metadata.gz: 9309d18f9110a2295d933c2464788a8cceb42161
4
+ data.tar.gz: 94bc5fd42d4c176312d80ca1a45733593a23a395
5
5
  SHA512:
6
- metadata.gz: 962203d2e16abf60f2b3b491bc3e14a1c229241609ff0701b3a736058d4bcd257ec2ec0174ffabdd938e7e1da60264ae118fc399ebd1d1f550d1d28142db0265
7
- data.tar.gz: 612fa5a8838f36dd8b5cb4ad2321791ecf450d6bc5c6872092ad730f94a8da36ff660b3644887377307cebe0b070e9dc267d32e2562f933651c0816a71e84d3c
6
+ metadata.gz: 7536f877ffa338b8195477b8c2e14ca9856a0b3f125941ad1fda48383cf5c883c9061f3934e6b3ec68de7ffb706d69faa08709edc88c821139ac76765e3e5c48
7
+ data.tar.gz: f6285300dd2b63c27705c6a2fdc7f0e263e1f52faf62a4d0d40e41fa2566367df994daae4eaaebece8635b8ca0e62d9a07ab7643c04117bcc4915acbc8bfbf9a
data/README.md CHANGED
@@ -178,13 +178,15 @@ override the default configuration inside the configuration
178
178
  The `foreman_tasks:cleanup` script also accepts additional parameters
179
179
  to specify the search criteria for the cleanup manually:
180
180
 
181
- * `FILTER`: scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
181
+ * `TASK_SEARCH`: scoped search filter (example: 'label =
182
+ "Actions::Foreman::Host::ImportFacts"')
182
183
  * `AFTER`: delete tasks created after `AFTER` period. Expected format
183
184
  is a number followed by the time unit (`s`, `h`, `m`, `y`), such as
184
- `10d` for 10 days (applicable only when the `FILTER` option is specified)
185
+ `10d` for 10 days (applicable only when the `TASK_SEARCH` option is
186
+ specified)
185
187
  * `STATES`: comma separated list of task states to touch with the
186
188
  cleanup, by default only stopped tasks are affected
187
- (applicable only when the `FILTER` option is specified)
189
+ (applicable only when the `TASK_SEARCH` option is specified)
188
190
  * `NOOP`: set to "true" if the task should not actuall perform the
189
191
  deletion, only report the actions the script would perform
190
192
  * `VERBOSE`: set to "true" for more verbose output
@@ -0,0 +1,26 @@
1
+ module ForemanTasks
2
+ module Concerns
3
+ module Parameters
4
+ module Triggering
5
+ extend ActiveSupport::Concern
6
+ include Foreman::Controller::Parameters::KeepParam
7
+
8
+ class_methods do
9
+ def triggering_params_filter
10
+ Foreman::ParameterFilter.new(::ForemanTasks::Triggering).tap do |filter|
11
+ filter.permit_by_context(:mode, :start_at, :start_before,
12
+ *::ForemanTasks::Triggering::PARAMS,
13
+ :nested => true)
14
+ end
15
+ end
16
+ end
17
+
18
+ def triggering_params
19
+ keep_param(params, :triggering, :days_of_week, :time, :end_time) do
20
+ self.class.triggering_params_filter.filter_params(params, parameter_filter_context, :triggering)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -4,7 +4,6 @@ module ForemanTasks
4
4
  :cronline, :days, :days_of_week, :time, :end_time_limited,
5
5
  :end_time]
6
6
  attr_accessor *PARAMS
7
- attr_accessible *PARAMS
8
7
 
9
8
  before_save do
10
9
  if future?
@@ -26,7 +26,7 @@ DESC
26
26
  s.test_files = `git ls-files test`.split("\n")
27
27
  s.extra_rdoc_files = Dir['README*', 'LICENSE']
28
28
 
29
- s.add_dependency "dynflow", '~> 0.8.8'
29
+ s.add_dependency "dynflow", '~> 0.8.13'
30
30
  s.add_dependency "sequel" # for Dynflow process persistence
31
31
  s.add_dependency "sinatra" # for Dynflow web console
32
32
  s.add_dependency "daemons" # for running remote executor
@@ -3,21 +3,21 @@ namespace :foreman_tasks do
3
3
  desc <<DESC
4
4
  Clean tasks based on filter and age. ENV variables:
5
5
 
6
- * FILTER : scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
7
- * AFTER : delete tasks created after *AFTER* period. Expected format is a number followed by the time unit (s,h,m,y), such as '10d' for 10 days
8
- * STATES : comma separated list of task states to touch with the cleanup, by default only stopped tasks are covered
9
- * NOOP : set to "true" if the task should not actuall perform the deletion
10
- * VERBOSE : set to "true" for more verbose output
11
- * BATCH_SIZE : the size of batches the tasks get processed in (1000 by default)
6
+ * TASK_SEARCH : scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
7
+ * AFTER : delete tasks created after *AFTER* period. Expected format is a number followed by the time unit (s,h,m,y), such as '10d' for 10 days
8
+ * STATES : comma separated list of task states to touch with the cleanup, by default only stopped tasks are covered
9
+ * NOOP : set to "true" if the task should not actuall perform the deletion
10
+ * VERBOSE : set to "true" for more verbose output
11
+ * BATCH_SIZE : the size of batches the tasks get processed in (1000 by default)
12
12
 
13
- If none of FILTER, BEFORE, STATES is specified, the tasks will be cleaned based
13
+ If none of TASK_SEARCH, BEFORE, STATES is specified, the tasks will be cleaned based
14
14
  configuration in settings
15
15
  DESC
16
16
  task :run => 'environment' do
17
17
  options = {}
18
18
 
19
- if ENV['FILTER']
20
- options[:filter] = ENV['FILTER']
19
+ if ENV['TASK_SEARCH']
20
+ options[:filter] = ENV['TASK_SEARCH']
21
21
  end
22
22
 
23
23
  if ENV['AFTER']
@@ -40,6 +40,10 @@ DESC
40
40
  options[:batch_size] = ENV['BATCH_SIZE'].to_i
41
41
  end
42
42
 
43
+ if ENV['FILTER']
44
+ fail "FILTER has been deprecated. Please use TASK_SEARCH instead."
45
+ end
46
+
43
47
  ForemanTasks::Cleaner.run(options)
44
48
  end
45
49
 
@@ -2,15 +2,31 @@
2
2
  # export_tasks.rake is a debugging tool to extract tasks from the
3
3
  # current foreman instance.
4
4
  #
5
- # Run "foreman-rake export_tasks" to export tasks whcih are not listed
6
- # as successful.
7
- # To export all tasks "foreman-rake export_tasks tasks=all"
8
- # to specify the number of days of tasks to gather: days=60 (defaults to 60)
5
+ # Run "foreman-rake foreman_tasks:export_tasks" to export tasks
9
6
 
10
- namespace :foreman_tasks do
11
- desc 'Export Dynflow Tasks'
7
+ require 'csv'
12
8
 
9
+ namespace :foreman_tasks do
10
+ desc <<DESC
11
+ Export dynflow tasks based on filter. ENV variables:
12
+
13
+ * TASK_SEARCH : scoped search filter (example: 'label = "Actions::Foreman::Host::ImportFacts"')
14
+ * TASK_FILE : file to export to
15
+ * TASK_FORMAT : format to use for the export (either html or csv)
16
+ * TASK_DAYS : number of days to go back
17
+
18
+ If TASK_SEARCH is not defined, it defaults to all tasks in the past 7 days and
19
+ all unsuccessful tasks in the past 60 days. The default TASK_FORMAT is html
20
+ which requires a tar.gz file extension.
21
+ DESC
13
22
  task :export_tasks => :environment do
23
+ deprecated_options = {:tasks => "TASK_SEARCH",
24
+ :days => "TASK_DAYS",
25
+ :export => "TASK_FILE"
26
+ }
27
+ deprecated_options.each do |option, new_option|
28
+ fail "The #{option} option is deprecated. Please use #{new_option} instead" if ENV.include?(option.to_s)
29
+ end
14
30
 
15
31
  class TaskRender
16
32
  def initialize
@@ -218,35 +234,50 @@ namespace :foreman_tasks do
218
234
  end
219
235
  end
220
236
 
221
-
222
- if ENV['tasks'] == 'all'
223
- tasks = ForemanTasks::Task
237
+ if ENV['TASK_SEARCH'].nil? && ENV['TASK_DAYS'].nil?
238
+ filter = "started_at > \"#{7.days.ago.to_s(:db)}\" || " \
239
+ "(result != success && started_at > \"#{60.days.ago.to_s(:db)})\""
224
240
  else
225
- tasks = ForemanTasks::Task.where("result != 'success'")
241
+ filter = ENV['TASK_SEARCH'] || ''
226
242
  end
227
243
 
228
- days = ENV['days'].try(:to_i) || 60
229
- tasks = tasks.where('started_at > ?', days.days.ago)
230
- export_filename = ENV['export'] || "/tmp/task-export-#{DateTime.now.to_i}.tar.gz"
244
+ if (days = ENV['TASK_DAYS'])
245
+ filter += " && " unless filter == ''
246
+ filter += "started_at > \"#{days.to_i.days.ago.to_s(:db)}\""
247
+ end
231
248
 
232
- puts _("Gathering last #{days} days of tasks.")
233
- Dir.mktmpdir('task-export') do |tmp_dir|
234
- PageHelper.copy_assets(tmp_dir)
249
+ format = ENV['TASK_FORMAT'] || 'html'
250
+ export_filename = ENV['TASK_FILE'] || "/tmp/task-export-#{DateTime.now.to_i}.#{format == 'csv' ? 'csv' : 'tar.gz'}"
235
251
 
252
+ tasks = ForemanTasks::Task.search_for(filter)
236
253
 
237
- renderer = TaskRender.new
238
- count = 1
239
- total = tasks.count
254
+ puts _("Gathering #{tasks.count} tasks.")
255
+ if format == 'html'
256
+ Dir.mktmpdir('task-export') do |tmp_dir|
257
+ PageHelper.copy_assets(tmp_dir)
240
258
 
241
- tasks.all.each do |task|
242
- File.open(File.join(tmp_dir, "#{task.id}.html"), 'w') {|file| file.write(PageHelper.pagify(renderer.render_task(task)))}
243
- puts "#{count}/#{total}"
244
- count += 1
245
- end
246
259
 
247
- File.open(File.join(tmp_dir, "index.html"), 'w') {|file| file.write(PageHelper.pagify(PageHelper.generate_index(tasks)))}
260
+ renderer = TaskRender.new
261
+ total = tasks.count
248
262
 
249
- sh("tar cvzf #{export_filename} #{tmp_dir} > /dev/null")
263
+ tasks.each_with_index do |task, count|
264
+ File.open(File.join(tmp_dir, "#{task.id}.html"), 'w') {|file| file.write(PageHelper.pagify(renderer.render_task(task)))}
265
+ puts "#{count + 1}/#{total}"
266
+ count += 1
267
+ end
268
+
269
+ File.open(File.join(tmp_dir, "index.html"), 'w') {|file| file.write(PageHelper.pagify(PageHelper.generate_index(tasks)))}
270
+
271
+ sh("tar cvzf #{export_filename} #{tmp_dir} > /dev/null")
272
+ end
273
+ elsif format == 'csv'
274
+ CSV.open(export_filename, 'wb') do |csv|
275
+ csv << ['id', 'state', 'type', 'label', 'result', 'parent_task_id', 'started_at', 'ended_at']
276
+ tasks.each do |task|
277
+ csv << [task.id, task.state, task.type, task.label, task.result,
278
+ task.parent_task_id, task.started_at, task.ended_at]
279
+ end
280
+ end
250
281
  end
251
282
 
252
283
  puts "Created #{export_filename}"
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = "0.7.20"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.20
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-22 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dynflow
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.8
19
+ version: 0.8.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.8
26
+ version: 0.8.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sequel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +105,7 @@ files:
105
105
  - app/controllers/foreman_tasks/api/tasks_controller.rb
106
106
  - app/controllers/foreman_tasks/concerns/environments_extension.rb
107
107
  - app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb
108
+ - app/controllers/foreman_tasks/concerns/parameters/triggering.rb
108
109
  - app/controllers/foreman_tasks/recurring_logics_controller.rb
109
110
  - app/controllers/foreman_tasks/tasks_controller.rb
110
111
  - app/helpers/foreman_tasks/foreman_tasks_helper.rb