lib/daemonic.rb in daemonic-0.1.1 vs lib/daemonic.rb in daemonic-0.1.2

- old
+ new

@@ -12,23 +12,24 @@ Thread.abort_on_exception = true module Daemonic - def self.run(worker, default_options = {}) + def self.run(default_options = {}, &worker_proc) command, options = CLI.new(ARGV, default_options).run case command - when :start then start(worker, options) + when :start then start(options, &worker_proc) when :stop then stop(options) when :status then status(options) - when :restart then restart(worker, options) + when :restart then restart(options, &worker_proc) end end - def self.start(worker, options) + def self.start(options, &worker_proc) daemon = Daemon.new(options) daemon.start do + worker = worker_proc.call Producer.new(worker, options).run end end def self.stop(options) @@ -37,12 +38,13 @@ def self.status(options) Daemon.new(options).status end - def self.restart(worker, options) + def self.restart(options, &worker_proc) daemon = Daemon.new(options.merge(daemonize: true)) daemon.restart do + worker = worker_proc.call Producer.new(worker, options).run end end end