aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-06-03 14:54:25 +0200
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-06-03 14:54:25 +0200
commit5a6863726ce3e56888200c25eb431912d1dce2ed (patch)
tree359c8e828a932f6794e08ee7af43df520c059f06
parentShow a meaningful error if the dataurl is nil. (diff)
downloadrbot-bugzilla-5a6863726ce3e56888200c25eb431912d1dce2ed.tar.gz
rbot-bugzilla-5a6863726ce3e56888200c25eb431912d1dce2ed.tar.bz2
rbot-bugzilla-5a6863726ce3e56888200c25eb431912d1dce2ed.zip
Add a cleanup function to the plugin.
The cleanup function is used during rescans so that the previous instance's timer is not still executed. The previous timer will not have any effect anyway, as it will find the BDB instance closed, but it will most likely waste time. The cleanup function is also ready to close the client connections for the various bugzillas, but at the moment httpclient does not provide any way to actually close the connection, so it's just a dummy function.
-rw-r--r--bugzilla.rb34
1 files changed, 27 insertions, 7 deletions
diff --git a/bugzilla.rb b/bugzilla.rb
index 9e5e9da..7a82e9d 100644
--- a/bugzilla.rb
+++ b/bugzilla.rb
@@ -125,7 +125,7 @@ class BugzillaPlugin < Plugin
def baseurl=(val)
val = val[0..-2] if val[-1].chr == '/'
@registry["zilla.#{name}.baseurl"] = val
- @client = nil
+ delete_client
end
def dataurl
@@ -140,7 +140,6 @@ class BugzillaPlugin < Plugin
def dataurl=(val)
@dataurl = @registry["zilla.#{name}.dataurl"] = val
- @client = nil
end
def showbugurl
@@ -155,7 +154,6 @@ class BugzillaPlugin < Plugin
def showbugurl=(val)
@showbugurl = @registry["zilla.#{name}.showbugurl"] = val
- @client = nil
end
def reporturl
@@ -170,7 +168,6 @@ class BugzillaPlugin < Plugin
def reporturl=(val)
@reporturl = @registry["zilla.#{name}.reporturl"] = val
- @client = nil
end
def useragent
@@ -182,7 +179,7 @@ class BugzillaPlugin < Plugin
def useragent=(val)
@registry["zilla.#{name}.useragent"] = val
- @client = nil
+ delete_client
end
def lastseenid
@@ -223,7 +220,6 @@ class BugzillaPlugin < Plugin
@name = name
end
-
# Guess at the public URL to show for a bug.
def guess_showbugurl
@showbugurl = baseurl
@@ -285,6 +281,16 @@ class BugzillaPlugin < Plugin
return @client
end
+ # Deletes the client object if any
+ def delete_client
+ # TODO: httpclient does not seem to provide a way to close the
+ # connection as of now, until that is implemented this is just a
+ # dummy function, and the plugin will leak connections on
+ # rescan.
+
+ @client = nil
+ end
+
# Return the summary for a given bug.
def summary(bugno)
raise EInvalidInstance.new(self.name, "No XML data URL available") if dataurl == nil
@@ -393,11 +399,25 @@ class BugzillaPlugin < Plugin
@registry["channel_defaults"] = Hash.new
end
- @bot.timer.add(300) {
+ @polling_timer = @bot.timer.add(300) {
poll_zillas
}
end
+ # Cleanup the plugin on reload
+ #
+ # This function is used to remove timers and close HTTPClient
+ # instances, otherwise they'll be kept open with no good reason.
+ def cleanup
+ @zillas.each do |zilla|
+ zilla.delete_client
+ end
+
+ @bot.timer.remove(@polling_timer)
+
+ super
+ end
+
# Check for the existence of zilla in the registry.
# This function checks if a given zilla is present in the registry
# file by checking for presence of a zilla. entry. It raises