Diff

mod_pubsub_feed/mod_pubsub_feed.lua @ 405:fe4fdba21a23

mod_pubsub_feed: Kill the timer on module unload
author Kim Alvefur <zash@zash.se>
date Sat, 27 Aug 2011 04:49:11 +0200
parent 403:fc62b26dfdf6
child 455:52f2188ec47d
line wrap: on
line diff
--- a/mod_pubsub_feed/mod_pubsub_feed.lua	Thu Aug 25 12:22:48 2011 +0500
+++ b/mod_pubsub_feed/mod_pubsub_feed.lua	Sat Aug 27 04:49:11 2011 +0200
@@ -52,6 +52,12 @@
 -- TODO module:hook("config-reloaded", above loop);
 -- Also, keeping it somewhere persistent in order to avoid duplicated publishes?
 
+-- Used to kill the timer
+local module_unloaded = false;
+function module.unload()
+	module_unloaded = true;
+end
+
 -- Thanks to Maranda for this
 local port, base, ssl = 5280, "callback", false;
 local ports = module:get_option("feeds_ports") or { port = port, base = base, ssl = ssl };
@@ -76,6 +82,7 @@
 	["400"] = "Bad Request";
 	["403"] = "Forbidden";
 	["404"] = "Not Found";
+	["500"] = "Internal Server Error";
 	["501"] = "Not Implemented";
 };
 
@@ -162,6 +169,7 @@
 end
 
 function refresh_feeds()
+	if module_unloaded then return end
 	--module:log("debug", "Refreshing feeds");
 	for node, item in pairs(feed_list) do
 		--FIXME Don't fetch feeds which have a subscription
@@ -202,6 +210,11 @@
 end
 
 function handle_http_request(method, body, request)
+	if module_unloaded then
+		module:log("warn", "Received a HTTP request after module unload");
+		return http_response(500)
+		-- FIXME if this happens.
+	end
 	--module:log("debug", "%s request to %s%s with body %s", method, request.url.path, request.url.query and "?" .. request.url.query or "", #body > 0 and body or "empty");
 	local query = request.url.query or {};
 	if query and type(query) == "string" then