Skip to content

Commit c2989e0

Browse files
committed
add hook to restart thread manually
1 parent fa07365 commit c2989e0

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/graphql-hive.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def on_exit
148148
@usage_reporter.on_exit
149149
end
150150

151+
def on_start
152+
@usage_reporter.on_start
153+
end
154+
151155
private
152156

153157
def initialize_options!(options)

lib/graphql-hive/usage_reporter.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,30 @@ def initialize(options, client)
2828
@options_mutex = Mutex.new
2929
@queue = Queue.new
3030

31-
start_consuming
31+
start_thread
3232
end
3333

3434
def add_operation(operation)
3535
@queue.push(operation)
36-
check_thread
3736
end
3837

3938
def on_exit
4039
@queue.close
4140
@thread.join
4241
end
4342

44-
private
43+
def on_start
44+
start_thread
45+
end
4546

46-
def check_thread
47-
return unless @thread.alive?
47+
private
4848

49-
@options[:logger].debug("buffer consuming thread died - restarting")
50-
start_consuming
51-
end
49+
def start_thread
50+
if @thread && @thread.alive?
51+
@options[:logger].warn("Thread already alive, no need to restart")
52+
return
53+
end
5254

53-
def start_consuming
5455
@thread = Thread.new do
5556
buffer = []
5657
while (operation = @queue.pop(false))

0 commit comments

Comments
 (0)