Sha256: a3a57e6d4deb0528fbe57ca5693e25aaca30b7aed34745f2e3779ca5d2e72c97

Contents?: true

Size: 901 Bytes

Versions: 117

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, 'orphaned 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

117 entries across 117 versions & 1 rubygems

Version Path
foreman_remote_execution-14.1.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-14.1.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-14.1.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-14.0.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-14.0.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.2.6 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-14.0.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.2.5 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.2.4 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.2.3 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.2.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-12.0.7 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.2.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.2.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-10.1.3 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-13.0.0 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-12.0.5 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-12.0.4 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-12.0.1 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb
foreman_remote_execution-12.0.2 app/models/concerns/foreman_remote_execution/foreman_tasks_cleaner_extensions.rb