Skip to content

Instantly share code, notes, and snippets.

@threetreeslight
Created August 21, 2014 08:16
Show Gist options
  • Save threetreeslight/34a16afacc58d8fd4714 to your computer and use it in GitHub Desktop.
Save threetreeslight/34a16afacc58d8fd4714 to your computer and use it in GitHub Desktop.
deamon DSL
require 'logger'
require 'rails'
require 'net/http'
require 'uri'
require 'pry'
class Daemon
def self.run &block
new &block
end
def initialize &block
log.level = Logger::DEBUG
Process.daemon # if ARGV.any? {|i| i == '-D' }
@pid = Process.pid
File.write "#{root}/tmp/pids/daemon.pid", @pid
instance_eval &block
end
def logging msg
log.info msg
end
private
def root
@root ||= APP_HOME
end
def log
@log ||= Logger.new("#{root}/log/job.log")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment