# HG changeset patch # User Kim Alvefur # Date 1343859924 -7200 # Node ID 1184fe8ebb2178cd068d664f13ec1ecec5df4026 # Parent 82d292e4f30fb019edc50a2337217a6dea9f9721 mod_pubsub_hub: Try to choose time until the next periodic check in a sane way diff -r 82d292e4f30f -r 1184fe8ebb21 mod_pubsub_hub/mod_pubsub_hub.lua --- a/mod_pubsub_hub/mod_pubsub_hub.lua Wed Aug 01 17:14:03 2012 +0200 +++ b/mod_pubsub_hub/mod_pubsub_hub.lua Thu Aug 02 00:25:24 2012 +0200 @@ -144,15 +144,14 @@ local function periodic() local now = time(); local next_check = now + max_lease; - local purge = false + local purge = false; for topic, callbacks in pairs(subs_by_topic) do for callback, subscription in pairs(callbacks) do if subscription.mode == "subscribed" then if subscription.expires < now then -- Subscription has expired, drop it. - purge = true - end - if subscription.expires < now + min_lease then + purge = true; + elseif subscription.expires < now + min_lease then -- Subscription set to expire soon, re-confirm it. local challenge = uuid(); local callback_url = callback .. (callback:match("%?") and "&" or "?") .. formencode{ @@ -168,7 +167,7 @@ end end); else - next_check = m_min(next_check, now - subscription.expires) + next_check = m_min(next_check, subscription.expires); end end end @@ -180,10 +179,11 @@ new_callbacks[callback] = subscription; end end - subs_by_topic[topic] = new_callbacks + subs_by_topic[topic] = new_callbacks; + purge = false; end end - return m_max(next_check - min_lease, min_lease); + return now - m_max(next_check - min_lease, min_lease); end local function on_notify(subscription, content)