Class: OsCtld::Commands::Event::Subscribe
- Inherits:
-
Base
- Object
- Base
- OsCtld::Commands::Event::Subscribe
show all
- Includes:
- OsCtl::Lib::Utils::Log
- Defined in:
- lib/osctld/commands/event/subscribe.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary
collapse
Methods inherited from Base
#base_execute, #call_cmd, #call_cmd!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, run, run!
Instance Method Details
#execute ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/osctld/commands/event/subscribe.rb', line 9
def execute
log(:info, :eventd, 'Subscribing client')
queue = Eventd.subscribe
client_handler.reply_ok('subscribed')
opts.delete(:cli)
loop do
event = queue.pop(timeout: 0.2)
if event.nil?
if @do_stop
Eventd.unsubscribe(queue)
return error('osctld is shutting down')
end
elsif !filter?(event)
next
elsif !client_handler.reply_ok(export_event(event))
break
end
end
log(:info, :eventd, 'Unsubscribing client')
Eventd.unsubscribe(queue)
ok
end
|
#export_event(e) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/osctld/commands/event/subscribe.rb', line 64
def export_event(e)
{
type: e.type,
opts: e.opts,
}
end
|
#filter?(event) ⇒ Boolean
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/osctld/commands/event/subscribe.rb', line 41
def filter?(event)
if opts[:type]
if opts[:type].is_a?(Array)
return false if opts[:type].include?(event.type)
else
return false if opts[:type] != event.type.to_s
end
end
if opts[:opts]
opts[:opts].each do |k, v|
if v.is_a?(Array)
return false if !v.include?(event.opts[k])
else
return false if v != event.opts[k]
end
end
end
true
end
|
#request_stop ⇒ Object
36
37
38
|
# File 'lib/osctld/commands/event/subscribe.rb', line 36
def request_stop
@do_stop = true
end
|