Class: SolidQueue::Execution

Inherits:
Record
  • Object
show all
Includes:
JobAttributes
Defined in:
app/models/solid_queue/execution.rb,
app/models/solid_queue/execution/dispatching.rb,
app/models/solid_queue/execution/job_attributes.rb

Defined Under Namespace

Modules: Dispatching, JobAttributes Classes: UndiscardableError

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

non_blocking_lock

Class Method Details

.create_all_from_jobs(jobs) ⇒ Object



20
21
22
# File 'app/models/solid_queue/execution.rb', line 20

def create_all_from_jobs(jobs)
  insert_all execution_data_from_jobs(jobs)
end

.discard_all_from_jobs(jobs) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'app/models/solid_queue/execution.rb', line 52

def discard_all_from_jobs(jobs)
  SolidQueue.instrument(:discard_all, jobs_size: jobs.size, status: type) do |payload|
    transaction do
      job_ids = lock_all_from_jobs(jobs)

      payload[:size] = discard_jobs job_ids
      where(job_id: job_ids).delete_all
    end
  end
end

.discard_all_in_batches(batch_size: 500) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/solid_queue/execution.rb', line 30

def discard_all_in_batches(batch_size: 500)
  pending = count
  discarded = 0

  SolidQueue.instrument(:discard_all, batch_size: batch_size, status: type, batches: 0, size: 0) do |payload|
    loop do
      transaction do
        job_ids = limit(batch_size).order(:job_id).lock.pluck(:job_id)
        discarded = discard_jobs job_ids

        where(job_id: job_ids).delete_all
        pending -= discarded

        payload[:size] += discarded
        payload[:batches] += 1
      end

      break if pending <= 0 || discarded == 0
    end
  end
end

.execution_data_from_jobs(jobs) ⇒ Object



24
25
26
27
28
# File 'app/models/solid_queue/execution.rb', line 24

def execution_data_from_jobs(jobs)
  jobs.collect do |job|
    attributes_from_job(job).merge(job_id: job.id)
  end
end

.typeObject



16
17
18
# File 'app/models/solid_queue/execution.rb', line 16

def type
  model_name.element.sub("_execution", "").to_sym
end

Instance Method Details

#discardObject



77
78
79
80
81
82
83
84
# File 'app/models/solid_queue/execution.rb', line 77

def discard
  SolidQueue.instrument(:discard, job_id: job_id, status: type) do
    with_lock do
      job.destroy
      destroy
    end
  end
end

#typeObject



73
74
75
# File 'app/models/solid_queue/execution.rb', line 73

def type
  self.class.type
end