Comparison

mod_pubsub_feeds/mod_pubsub_feeds.lua @ 5572:fd1c535dcb92

mod_pubsub_feeds: Create pubsub nodes on module load instead of later Should produce faster feedback of things being wrong.
author Kim Alvefur <zash@zash.se>
date Sun, 25 Jun 2023 16:41:50 +0200
parent 5571:ca3c2d11823c
child 5573:ed177fa5b54c
comparison
equal deleted inserted replaced
5571:ca3c2d11823c 5572:fd1c535dcb92
59 if type(node) == "number" then 59 if type(node) == "number" then
60 node = url; 60 node = url;
61 end 61 end
62 new_feed_list[node] = true; 62 new_feed_list[node] = true;
63 if not feed_list[node] then 63 if not feed_list[node] then
64 feed_list[node] = { url = url; node = node; last_update = 0 }; 64 local ok, err = pubsub.service:create(node, true);
65 if ok then
66 feed_list[node] = { url = url; node = node; last_update = 0 };
67 else
68 module:log("error", "Could not create node %s: %s", node, err);
69 end
65 else 70 else
66 feed_list[node].url = url; 71 feed_list[node].url = url;
67 end 72 end
68 if not nodes[node] then 73 if not nodes[node] then
69 feed_list[node].last_update = 0; 74 feed_list[node].last_update = 0;
89 for entry in feed:childtags("entry") do 94 for entry in feed:childtags("entry") do
90 table.insert(entries, entry); 95 table.insert(entries, entry);
91 end 96 end
92 local ok, items = pubsub.service:get_items(node, true); 97 local ok, items = pubsub.service:get_items(node, true);
93 if not ok then 98 if not ok then
94 local ok, err = pubsub.service:create(node, true); 99 module:log("error", "PubSub node %q missing: %s", node, items);
95 if not ok then 100 return
96 module:log("error", "Could not create node %s: %s", node, err);
97 return;
98 end
99 items = {};
100 end 101 end
101 102
102 local start_from = #entries; 103 local start_from = #entries;
103 for i, entry in ipairs(entries) do 104 for i, entry in ipairs(entries) do
104 local id = entry:get_child_text("id"); 105 local id = entry:get_child_text("id");