Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 3450ff4

Browse files
author
Ahmed Ammar
committed
Rework exit logic.
1 parent 318980b commit 3450ff4

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

lib/logstash/inputs/dynamodb.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,25 @@ def register
182182

183183
public
184184
def run(logstash_queue)
185-
$exit = false
185+
$exit = false;
186+
$logstash_queue = logstash_queue
186187
run_with_catch(logstash_queue)
187188
end
188189

189190
public
190191
def stop
191192
$exit = true
192-
exit_threads
193+
194+
until @scan_queue.empty?
195+
end
196+
193197
until @queue.empty?
194198
@logger.info("Flushing rest of events in logstash queue")
195199
event = @queue.pop()
196-
queue_event(@parser.parse_stream(event), logstash_queue, @host)
200+
queue_event(@parser.parse_stream(event), $logstash_queue, @host)
197201
end # until [email protected]?
202+
203+
exit_threads
198204
end
199205

200206
# Starts KCL app in a background thread
@@ -261,7 +267,7 @@ def setup_stream
261267

262268
kcl_config = KCL::KinesisClientLibConfiguration.new(@checkpointer, stream_arn, @credentials, worker_id) \
263269
.withInitialPositionInStream(KCL::InitialPositionInStream::TRIM_HORIZON)
264-
cloudwatch_client = nil
270+
cloudwatch_client = nil
265271
if @publish_metrics
266272
cloudwatch_client = CloudWatch::AmazonCloudWatchClient.new(@credentials)
267273
else
@@ -280,10 +286,10 @@ def scan(logstash_queue)
280286
@connector = DynamoDBBootstrap::DynamoDBBootstrapWorker.new(@dynamodb_client, @read_ops, @table_name, @number_of_scan_threads)
281287
start_table_copy_thread
282288

283-
scan_queue = @logstash_writer.getQueue()
284-
while !$exit
285-
if !scan_queue.empty?
286-
event = scan_queue.take()
289+
@scan_queue = @logstash_writer.getQueue()
290+
while true
291+
if !@scan_queue.empty?
292+
event = @scan_queue.take()
287293
if event.getEntry().nil? and event.getSize() == -1
288294
break
289295
end # if event.isEmpty()
@@ -311,7 +317,9 @@ def stream(logstash_queue)
311317

312318
private
313319
def exit_threads
314-
@worker.shutdown()
320+
unless @worker.nil?
321+
@worker.shutdown()
322+
end # unless @worker.nil?
315323

316324
unless @dynamodb_scan_thread.nil?
317325
@dynamodb_scan_thread.exit

0 commit comments

Comments
 (0)