Class: SolidQueue::ClaimedExecution

Inherits:
Execution show all
Defined in:
app/models/solid_queue/claimed_execution.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Execution

create_all_from_jobs, execution_data_from_jobs, type, #type

Methods inherited from Record

non_blocking_lock

Class Method Details

.claiming(job_ids, process_id, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/solid_queue/claimed_execution.rb', line 15

def claiming(job_ids, process_id, &block)
  job_data = Array(job_ids).collect { |job_id| { job_id: job_id, process_id: process_id } }

  SolidQueue.instrument(:claim, process_id: process_id, job_ids: job_ids) do |payload|
    insert_all!(job_data)
    where(job_id: job_ids, process_id: process_id).load.tap do |claimed|
      block.call(claimed)

      payload[:size] = claimed.size
      payload[:claimed_job_ids] = claimed.map(&:job_id)
    end
  end
end

.discard_all_from_jobsObject

Raises:



55
56
57
# File 'app/models/solid_queue/claimed_execution.rb', line 55

def discard_all_from_jobs(*)
  raise UndiscardableError, "Can't discard jobs in progress"
end

.discard_all_in_batchesObject

Raises:



51
52
53
# File 'app/models/solid_queue/claimed_execution.rb', line 51

def discard_all_in_batches(*)
  raise UndiscardableError, "Can't discard jobs in progress"
end

.fail_all_with(error) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/solid_queue/claimed_execution.rb', line 39

def fail_all_with(error)
  SolidQueue.instrument(:fail_many_claimed) do |payload|
    includes(:job).tap do |executions|
      executions.each { |execution| execution.failed_with(error) }

      payload[:process_ids] = executions.map(&:process_id).uniq
      payload[:job_ids] = executions.map(&:job_id).uniq
      payload[:size] = executions.size
    end
  end
end

.release_allObject



29
30
31
32
33
34
35
36
37
# File 'app/models/solid_queue/claimed_execution.rb', line 29

def release_all
  SolidQueue.instrument(:release_many_claimed) do |payload|
    includes(:job).tap do |executions|
      executions.each(&:release)

      payload[:size] = executions.size
    end
  end
end

Instance Method Details

#discardObject

Raises:



82
83
84
# File 'app/models/solid_queue/claimed_execution.rb', line 82

def discard
  raise UndiscardableError, "Can't discard a job in progress"
end

#failed_with(error) ⇒ Object



86
87
88
89
90
91
# File 'app/models/solid_queue/claimed_execution.rb', line 86

def failed_with(error)
  transaction do
    job.failed_with(error)
    destroy!
  end
end

#performObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/solid_queue/claimed_execution.rb', line 60

def perform
  result = execute

  if result.success?
    finished
  else
    failed_with(result.error)
    raise result.error
  end
ensure
  job.unblock_next_blocked_job
end

#releaseObject



73
74
75
76
77
78
79
80
# File 'app/models/solid_queue/claimed_execution.rb', line 73

def release
  SolidQueue.instrument(:release_claimed, job_id: job.id, process_id: process_id) do
    transaction do
      job.dispatch_bypassing_concurrency_limits
      destroy!
    end
  end
end