Class: SolidQueue::BlockedExecution

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Execution

create_all_from_jobs, #discard, discard_all_from_jobs, discard_all_in_batches, execution_data_from_jobs, type, #type

Methods inherited from Record

non_blocking_lock

Class Method Details

.release_many(concurrency_keys) ⇒ Object



21
22
23
24
25
# File 'app/models/solid_queue/blocked_execution.rb', line 21

def release_many(concurrency_keys)
  # We want to release exactly one blocked execution for each concurrency key, and we need to do it
  # one by one, locking each record and acquiring the semaphore individually for each of them:
  Array(concurrency_keys).count { |concurrency_key| release_one(concurrency_key) }
end

.release_one(concurrency_key) ⇒ Object



27
28
29
30
31
32
33
# File 'app/models/solid_queue/blocked_execution.rb', line 27

def release_one(concurrency_key)
  transaction do
    if execution = ordered.where(concurrency_key: concurrency_key).limit(1).non_blocking_lock.first
      execution.release
    end
  end
end

.unblock(limit) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/solid_queue/blocked_execution.rb', line 13

def unblock(limit)
  SolidQueue.instrument(:release_many_blocked, limit: limit) do |payload|
    expired.distinct.limit(limit).pluck(:concurrency_key).then do |concurrency_keys|
      payload[:size] = release_many releasable(concurrency_keys)
    end
  end
end

Instance Method Details

#releaseObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/solid_queue/blocked_execution.rb', line 44

def release
  SolidQueue.instrument(:release_blocked, job_id: job.id, concurrency_key: concurrency_key, released: false) do |payload|
    transaction do
      if acquire_concurrency_lock
        promote_to_ready
        destroy!

        payload[:released] = true
      end
    end
  end
end