Module: Healthety
- Extended by:
- Healthety
- Included in:
- Healthety
- Defined in:
- lib/healthety/worker.rb,
lib/healthety/version.rb,
lib/healthety/healthety.rb,
lib/healthety/transmission.rb
Defined Under Namespace
Classes: Transmission, Worker
Constant Summary
collapse
- VERSION =
"0.0.7"
Instance Method Summary
collapse
Instance Method Details
#helpers(*extensions) ⇒ Object
Makes the methods defined in the helper modules given in ‘extensions` available to the workers.
35
36
37
|
# File 'lib/healthety/healthety.rb', line 35
def helpers(*extensions)
Worker.class_eval { include(*extensions) } if extensions.any?
end
|
#host(host) ⇒ Object
21
22
23
|
# File 'lib/healthety/healthety.rb', line 21
def host(host)
@host = host
end
|
#message ⇒ Object
58
59
60
61
62
63
|
# File 'lib/healthety/healthety.rb', line 58
def message
<<-EOM
=> Workers sending to #{@host}:#{@port}
=> Ctrl-C to stop
EOM
end
|
#port(port) ⇒ Object
25
26
27
|
# File 'lib/healthety/healthety.rb', line 25
def port(port)
@port = port
end
|
#start ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/healthety/healthety.rb', line 39
def start
transmission = Transmission.new(@host, @port)
trap("INT") { @threads.map(&:kill) }
@workers.each do |worker|
@threads << Thread.new do
loop do
worker.perform
transmission.send(worker.name, worker.value)
sleep worker.interval
end
end
end
@threads.map(&:join)
end
|
#worker(name, &block) ⇒ Object
29
30
31
|
# File 'lib/healthety/healthety.rb', line 29
def worker(name, &block)
@workers << Worker.new(name, &block)
end
|
#workers(&block) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/healthety/healthety.rb', line 6
def workers(&block)
@workers = []
@threads = []
instance_eval(&block)
if ARGV.any?
Daemons.run_proc("healthety") { start }
else
puts message
start
end
end
|