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.3"

Class Method Summary collapse

Class Method Details

.restart(options, &worker_proc) ⇒ Object



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

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

.run(default_options = {}, &worker_proc) ⇒ Object



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

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

.start(options, &worker_proc) ⇒ Object



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

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

.status(options) ⇒ Object



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

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

.stop(options) ⇒ Object



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

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