DEV: Review fixes (#10641)

See comments in https://review.discourse.org/t/dev-imap-log-to-database-10435/14337/6 for context.
This commit is contained in:
Martin Brennan
2020-09-10 13:41:46 +10:00
committed by GitHub
parent e6ca1b4326
commit 7f2f87bf59
4 changed files with 25 additions and 19 deletions

View File

@ -68,9 +68,7 @@ class Demon::EmailSync < ::Demon::Base
@sync_data.each do |db, sync_data|
sync_data.each do |_, data|
data[:thread].kill
data[:thread].join
data[:syncer]&.disconnect! rescue nil
kill_and_disconnect!(data)
end
end
@ -104,9 +102,7 @@ class Demon::EmailSync < ::Demon::Base
next true if all_dbs.include?(db)
sync_data.each do |_, data|
data[:thread].kill
data[:thread].join
data[:syncer]&.disconnect!
kill_and_disconnect!(data)
end
false
@ -130,10 +126,7 @@ class Demon::EmailSync < ::Demon::Base
ImapSyncLog.warn("Thread for group is dead", group_id)
end
data[:thread].kill
data[:thread].join
data[:syncer]&.disconnect!
kill_and_disconnect!(data)
false
end
@ -166,4 +159,14 @@ class Demon::EmailSync < ::Demon::Base
STDERR.puts e.backtrace.join("\n")
exit 1
end
def kill_and_disconnect!(data)
data[:thread].kill
data[:thread].join
begin
data[:syncer]&.disconnect!
rescue Net::IMAP::ResponseError => err
puts "[EmailSync] Encountered a response error when disconnecting: #{err.to_s}"
end
end
end