Sha256: 0202f0cf546946dde12e3f96d0628ce04cdd4aeda6b4b2ebca2cad850b30c49a

Contents?: true

Size: 1.03 KB

Versions: 12

Compression:

Stored size: 1.03 KB

Contents

module ForemanRemoteExecution
  module ForemanTasksCleanerExtensions
    extend ActiveSupport::Concern

    included do
      prepend ForemanRemoteExecution::JobInvocationCleaner
    end
  end

  module JobInvocationCleaner
    def delete
      super
      if noop
        say '[noop] deleting orphaned job invocations'
        say "[noop] #{orphaned_job_invocations.count} job invocations would be deleted"
      else
        count = orphaned_job_invocations.count
        orphaned_job_invocations.find_each(&:destroy)
        say "deleted #{count} orphaned job_invocations", false if verbose
      end
    end

    def delete_tasks(chunk)
      super(chunk)
      delete_job_invocations(chunk)
    end

    def delete_job_invocations(chunk)
      JobInvocation.where(:task_id => chunk.map(&:id)).find_each(&:destroy)
    end

    def orphaned_job_invocations
      JobInvocation.joins('LEFT JOIN foreman_tasks_tasks ON task_id = foreman_tasks_tasks.id')
                   .where('task_id IS NOT NULL and foreman_tasks_tasks.id IS NULL')
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman_remote_execution-1.4.6 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.4.5 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.4.4 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.4.3 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.4.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.3.7 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.3.6 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.4.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.3.5 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.3.4 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.3.3 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.3.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb