Created
August 21, 2014 08:16
-
-
Save threetreeslight/34a16afacc58d8fd4714 to your computer and use it in GitHub Desktop.
deamon DSL
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
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