Class: Harbor::Script
- Inherits:
-
Object
- Object
- Harbor::Script
- Includes:
- Thin::Daemonizable
- Defined in:
- lib/harbor/script.rb
Overview
Class for defining and running daemonizable scripts.
services = Harbor::Container.new
services.register("mailer", Harbor::Mailer)
class Processor < Harbor::Script
attr_accessor :mailer
def self.pid_file
"tmp/processor.pid"
end
def self.log_file
"log/processor.log"
end
def self.run!
loop do
# processing code
end
end
end
Harbor::Script::Runner.new(ARGV, services, Processor).run!
Defined Under Namespace
Classes: Runner
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#services ⇒ Object
Returns the value of attribute services.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Script
constructor
A new instance of Script.
- #log(message) ⇒ Object
- #logger ⇒ Object
- #name ⇒ Object
- #run! ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Script
Returns a new instance of Script.
69 70 71 72 73 74 75 76 |
# File 'lib/harbor/script.rb', line 69 def initialize @on_restart = lambda do exec("#{$0} #{'--daemonize' if @options[:daemonize]} start") end @pid_file = self.class.pid_file @log_file = self.class.log_file end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
45 46 47 |
# File 'lib/harbor/script.rb', line 45 def end |
#services ⇒ Object
Returns the value of attribute services.
45 46 47 |
# File 'lib/harbor/script.rb', line 45 def services @services end |
Class Method Details
.log_file ⇒ Object
65 66 67 |
# File 'lib/harbor/script.rb', line 65 def self.log_file raise NotImplementedError.new("#{self}#log_file must be defined.") end |
.logger ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/harbor/script.rb', line 47 def self.logger @logger ||= begin logger = Logging::Logger[self] logger.additive = false logger.level = :info logger.add_appenders(Logging::Appenders::Stdout.new) logger end end |
.pid_file ⇒ Object
61 62 63 |
# File 'lib/harbor/script.rb', line 61 def self.pid_file raise NotImplementedError.new("#{self}#pid_file must be defined.") end |
Instance Method Details
#log(message) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/harbor/script.rb', line 78 def log() if [:daemonize] self.class.logger << + "\n" else puts end end |
#logger ⇒ Object
57 58 59 |
# File 'lib/harbor/script.rb', line 57 def logger self.class.logger end |
#name ⇒ Object
86 87 88 |
# File 'lib/harbor/script.rb', line 86 def name $0 end |
#run! ⇒ Object
94 95 96 |
# File 'lib/harbor/script.rb', line 94 def run! raise NotImplementedError.new("#{self}.run! must be defined.") end |
#stop ⇒ Object
90 91 92 |
# File 'lib/harbor/script.rb', line 90 def stop log ">> Stopping" end |