Class: SolidQueue::Process

Inherits:
Record
  • Object
show all
Includes:
Executor, Prunable
Defined in:
app/models/solid_queue/process.rb,
app/models/solid_queue/process/executor.rb,
app/models/solid_queue/process/prunable.rb

Defined Under Namespace

Modules: Executor, Prunable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Executor

#fail_all_claimed_executions_with, #release_all_claimed_executions

Methods included from Prunable

#prune

Methods inherited from Record

non_blocking_lock

Class Method Details

.register(**attributes) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'app/models/solid_queue/process.rb', line 11

def self.register(**attributes)
  SolidQueue.instrument :register_process, **attributes do |payload|
    create!(attributes.merge(last_heartbeat_at: Time.current)).tap do |process|
      payload[:process_id] = process.id
    end
  rescue Exception => error
    payload[:error] = error
    raise
  end
end

Instance Method Details

#deregister(pruned: false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/solid_queue/process.rb', line 30

def deregister(pruned: false)
  SolidQueue.instrument :deregister_process, process: self, pruned: pruned do |payload|
    destroy!

    unless supervised? || pruned
      supervisees.each(&:deregister)
    end
  rescue Exception => error
    payload[:error] = error
    raise
  end
end

#heartbeatObject



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

def heartbeat
  # Clear any previous changes before locking, for example, in case a previous heartbeat
  # failed because of a DB issue (with SQLite depending on configuration, a BusyException
  # is not rare) and we still have the unpersisted value
  restore_attributes
  with_lock { touch(:last_heartbeat_at) }
end