Class: Gouda::EmptyQueueShutdownCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/gouda/worker.rb

Overview

This shutdown check will return ‘true` once there are no enqueued jobs to process for this worker. This can be used to run a worker just as long as there are jobs to handle and then to let it quit by itself (handy for spot instances and the like)

Instance Method Summary collapse

Constructor Details

#initialize(queue_constraint = Gouda::AnyQueue) ⇒ EmptyQueueShutdownCheck

Returns a new instance of EmptyQueueShutdownCheck.



81
82
83
# File 'lib/gouda/worker.rb', line 81

def initialize(queue_constraint = Gouda::AnyQueue)
  @queue_constraint = queue_constraint
end

Instance Method Details

#callObject



85
86
87
88
89
90
91
92
93
# File 'lib/gouda/worker.rb', line 85

def call
  # return false unless Rails.application # Rails is still booting and there is no application defined

  Gouda.config.app_executor.wrap do
    Gouda::Workload.waiting_to_start(queue_constraint: @queue_constraint).none?
  end
rescue # If the DB connection cannot be checked out etc
  false
end