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
94
# File 'lib/gouda/worker.rb', line 85

def call
  Gouda.config.app_executor.wrap do
    Gouda.suppressing_sql_logs { Gouda::Workload.waiting_to_start(queue_constraint: @queue_constraint).none? }
  end
rescue
  # It is possible that in this scenario we do not have a database set up yet, for example,
  # or we are unable to connect to the DB for whatever reason. In that case we should
  # return `false` so that the worker can poll again later.
  false
end