-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathevents_task.rb
More file actions
50 lines (41 loc) · 1.3 KB
/
events_task.rb
File metadata and controls
50 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
module SplitIoClient
module Engine
module Events
class EventsTask
attr_accessor :running
def initialize(notify_internal_events, internal_events_queue, config)
@notify_internal_events = notify_internal_events
@internal_events_queue = internal_events_queue
@config = config
@running = false
end
def start
return if @running
@config.logger.info('Starting Internal Events Task.')
@running = true
@config.threads[:internal_events_task] = Thread.new do
worker_thread
end
end
def stop
return unless @running
@config.logger.info('Stopping Internal Events Task.')
@running = false
end
private
def worker_thread
while (event = @internal_events_queue.pop)
break unless @running
@config.logger.debug("Processing sdk internal event: #{event.internal_event}") if @config.debug_enabled
begin
@notify_internal_events.call(event.internal_event, event.metadata)
rescue StandardError => e
@config.log_found_exception(__method__.to_s, e)
end
end
end
end
end
end
end