8000 Make quitting daemon friendly by akshetpandey · Pull Request #195 · cinchrb/cinch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 13, 2019. It is now read-only.

Make quitting daemon friendly #195 8000

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/cinch/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Bot < User
# @return [Boolean] whether the bot is in the process of disconnecting
attr_reader :quitting

# @return [String] quit message to send to server
attr_reader :quit_message

# @return [UserList] All {User users} the bot knows about.
# @see UserList
# @since 1.1.0
Expand Down Expand Up @@ -224,9 +227,7 @@ def configure
# @return [void]
def quit(message = nil)
@quitting = true
command = message ? "QUIT :#{message}" : "QUIT"

@irc.send command
@quit_command = message ? "QUIT :#{message}" : "QUIT"
end

# Connects the bot to a server.
Expand Down
15 changes: 15 additions & 0 deletions lib/cinch/irc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ def start_ping_thread
end
end

# @api private
# @return [Thread] The quit thread.
# @since 2.0.0
def start_quit_thread
Thread.new do
# Check every 1 second if the bot needs to be shut down.
while !@bot.quitting
sleep 1
end
self.send @bot.quit_message
end
end

# @since 2.0.0
def send_sasl
if @bot.config.sasl.username && @sasl_current_method = @sasl_remaining_methods.pop
Expand All @@ -217,10 +230,12 @@ def start
reading_thread = start_reading_thread
sending_thread = start_sending_thread
ping_thread = start_ping_thread
quit_thread = start_quit_thread

reading_thread.join
sending_thread.kill
ping_thread.kill
quit_thread.kill
end
end

Expand Down
0