#!/usr/bin/env ruby # frozen_string_literal: true require 'bundler/setup' require_relative '../config/environment' require 'rack' # Take the whole script down if anything goes remotely wrong Thread.abort_on_exception = true MACCHIATO_PORT = 4000 # Health Check: A rack app that listens on 4000 # and returns 200 to indicate it's alive. _health_check_thread = Thread.new do headers = { 'Content-Type' => 'text/plain' }.freeze response = ['200', headers, 'Alive'].freeze app = proc { |_env| response } Rack::Handler::WEBrick.run app, Port: MACCHIATO_PORT end # Worker Job: A thread that initiates the DelayedJob worker queue. delayed_job_options = { quiet: false }.freeze worker_thread = Thread.new { Delayed::Worker.new(delayed_job_options).start } # Wait for the worker queue thread to finish before ending the script. # If it crashes, the script will end and take the health check thread # down as well. worker_thread.join