Sha256: 6f952ea0ab8cf4f68559c71a88a437350b20369eb2babc7b66d04fbe2e2b8875

Contents?: true

Size: 1.19 KB

Versions: 109

Compression:

Stored size: 1.19 KB

Contents

#
# generate_task_actions.rake is a data migration task to properly fill the missing
# values into the foreman_tasks_tasks table.
#
# Run "foreman-rake foreman_tasks:generate_task_actions" to generate missing values.

namespace :foreman_tasks do
  desc 'Generate missing values for action column in foreman_tasks_tasks table.'

  BATCH_SIZE = 100

  task :generate_task_actions => :environment do
    class ProgressReporter
      def initialize(count, message = nil)
        @count = count
        @processed = 0
        puts message % { :count => count } unless message.nil?
      end

      def progress(count)
        @processed += count
      end

      def report
        puts _('Processed %{processed}/%{count} tasks') % { :processed => @processed, :count => @count }
      end
    end

    scope = ::ForemanTasks::Task.where(:action => nil).order(:started_at => :desc)
    count = scope.count
    reporter = ProgressReporter.new count, _('Generating action for %{count} tasks.')
    scope.find_in_batches(:batch_size => BATCH_SIZE) do |group|
      group.each do |task|
        task.action = task.to_label
        task.save!
      end
      reporter.progress group.size
      reporter.report
    end
  end
end

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-10.0.1 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-10.0.0 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.2.3 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.2.2 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.2.1 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.2.0 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.1.1 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.0.4 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.1.0 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.0.2 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.0.1 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-8.3.3 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-9.0.0 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-8.2.1 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-8.1.4 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-8.3.2 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-8.3.1 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-8.1.3 lib/foreman_tasks/tasks/generate_task_actions.rake
foreman-tasks-8.3.0 lib/foreman_tasks/tasks/generate_task_actions.rake