Created
October 27, 2016 23:24
-
-
Save anicholson/1ec2526edb5a573f9c20a10c54a82bdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment