comparison mod_pubsub_feed/mod_pubsub_feed.lua @ 300:b81e4f86a231

mod_pubsub_feed: Catch and handle errors when publishing
author Kim Alvefur <zash@zash.se>
date Sun, 26 Dec 2010 19:05:39 +0100
parents 801066bf5793
children 637dc0a04052
comparison
equal deleted inserted replaced
299:801066bf5793 300:b81e4f86a231
71 local id = entry:get_child("id"); 71 local id = entry:get_child("id");
72 id = id[1] or item.url.."#"..dt_datetime(timestamp); -- Missing id, so make one up 72 id = id[1] or item.url.."#"..dt_datetime(timestamp); -- Missing id, so make one up
73 local item = st.stanza("item", { id = id }):add_child(entry); 73 local item = st.stanza("item", { id = id }):add_child(entry);
74 74
75 module:log("debug", "publishing to %s, id %s", node, id); 75 module:log("debug", "publishing to %s, id %s", node, id);
76 modules.pubsub.service:publish(node, actor, id, item) 76 local ok, err = modules.pubsub.service:publish(node, actor, id, item);
77 if not ok then
78 if err == "item-not-found" then -- try again
79 module:log("debug", "got item-not-found, creating %s and trying again", node);
80 local ok, err = modules.pubsub.service:create(node, actor);
81 if not ok then
82 module:log("error", "could not create node: %s", err);
83 return;
84 end
85 local ok, err = modules.pubsub.service:publish(node, actor, id, item);
86 if not ok then
87 module:log("error", "still could not create node: %s", err);
88 return
89 end
90 else
91 module:log("error", "publish failed: %s", err);
92 end
93 end
77 end 94 end
78 end 95 end
79 end); 96 end);
80 end 97 end
81 return refresh_interval; 98 return refresh_interval;