Module: Daemonic

Defined in:
lib/daemonic/pool.rb,
lib/daemonic.rb,
lib/daemonic/cli.rb,
lib/daemonic/daemon.rb,
lib/daemonic/version.rb,
lib/daemonic/producer.rb

Overview

Stolen from RubyTapas by Avdi Grimm, episode 145.

Defined Under Namespace

Classes: CLI, Daemon, Pool, Producer

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.restart(worker, options) ⇒ Object



42
43
44
45
46
47
# File 'lib/daemonic.rb', line 42

def self.restart(worker, options)
  daemon = Daemon.new(options.merge(daemonize: true))
  daemon.restart do
    Producer.new(worker, options).run
  end
end

.run(worker, default_options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/daemonic.rb', line 17

def self.run(worker, default_options = {})
  command, options = CLI.new(ARGV, default_options).run
  case command
  when :start   then start(worker, options)
  when :stop    then stop(options)
  when :status  then status(options)
  when :restart then restart(worker, options)
  end
end

.start(worker, options) ⇒ Object



27
28
29
30
31
32
# File 'lib/daemonic.rb', line 27

def self.start(worker, options)
  daemon = Daemon.new(options)
  daemon.start do
    Producer.new(worker, options).run
  end
end

.status(options) ⇒ Object



38
39
40
# File 'lib/daemonic.rb', line 38

def self.status(options)
  Daemon.new(options).status
end

.stop(options) ⇒ Object



34
35
36
# File 'lib/daemonic.rb', line 34

def self.stop(options)
  Daemon.new(options).stop
end