class Service < Async::Service::Generic
- Inherits from
Async::Service::Generic
A job server that can be run as a service.
Definitions
def start
Preload the application before worker processes are forked.
Implementation
def start
Array(@evaluator.preload).each do |path|
require File.expand_path(path, @evaluator.root)
end
super
end
def setup(container)
Load the Rails environment and start the job server.
Implementation
def setup(container)
container_options = @evaluator.container_options
health_check_timeout = container_options[:health_check_timeout]
container.run(name: self.name, **container_options) do |instance|
evaluator = @environment.evaluator
require File.expand_path("config/environment", evaluator.root)
dispatcher = evaluator.dispatcher
instance.ready!
Sync do |task|
if health_check_timeout
task.async(transient: true) do
while true
instance.name = "#{self.name} (#{dispatcher.status_string})"
sleep(health_check_timeout / 2)
instance.ready!
end
end
end
barrier = Async::Barrier.new
# Start all the named queues:
evaluator.queue_names.each do |queue_name|
barrier.async do
Console.debug(self, "Starting queue...", queue_name: queue_name)
dispatcher.start(queue_name)
rescue => error
Console.error(self, "Failed to start queue!", queue_name: queue_name, exception: error)
end
end
barrier.wait or sleep
ensure
barrier&.stop
end
end
end