Sha256: 734838367a53c40ab1b0bd5ddc5f231f6a08c2305aea06e62851d3446a64ceb1

Contents?: true

Size: 901 Bytes

Versions: 19

Compression:

Stored size: 901 Bytes

Contents

module ForemanRemoteExecution
  module ForemanTasksCleanerExtensions
    extend ActiveSupport::Concern

    included do
      prepend ForemanRemoteExecution::JobInvocationCleaner
    end
  end

  module JobInvocationCleaner
    def delete
      super
      with_noop(orphaned_job_invocations, 'oprhaned job invocations') do |source, name|
        with_batches(source, name) do |invocations|
          invocations.destroy_all
        end
      end
    end

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

    def delete_job_invocations(tasks)
      JobInvocation.where(:task_id => tasks.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

19 entries across 19 versions & 1 rubygems

Version Path
foreman_remote_execution-1.8.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.8.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.7.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.7.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.7 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.6 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.5 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.4 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.5.6 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.3 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.5.5 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.6.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.5.4 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.5.3 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.5.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.5.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-1.5.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb