comparison plugins/mod_cron.lua @ 13364:6f9b15757384

mod_cron: Add shell command to list registered cron tasks with status
author Matthew Wild <mwild1@gmail.com>
date Thu, 30 Nov 2023 11:38:59 +0000
parents ffd3dadf6247
children fda192db8f18
comparison
equal deleted inserted replaced
13363:2738dda885bb 13364:6f9b15757384
73 end 73 end
74 end 74 end
75 module:log("debug", "Wait %ds", delay); 75 module:log("debug", "Wait %ds", delay);
76 return delay 76 return delay
77 end); 77 end);
78
79 module:add_item("shell-command", {
80 section = "cron";
81 section_desc = "View and manage recurring tasks";
82 name = "tasks";
83 desc = "View registered tasks";
84 args = {};
85 handler = function (self, host)
86 local format_table = require "prosody.util.human.io".table;
87 local it = require "util.iterators";
88 local row = format_table({
89 { title = "Host", width = "2p" };
90 { title = "Task", width = "3p" };
91 { title = "Desc", width = "3p" };
92 { title = "When", width = "1p" };
93 { title = "Last run", width = "20" };
94 }, self.session.width);
95 local print = self.session.print;
96 print(row());
97 for host in it.sorted_pairs(host and { [host]=true } or active_hosts) do
98 for _, task in ipairs(module:context(host):get_host_items("task")) do
99 print(row { host, task.id, task.name, task.when, task.last and os.date("%Y-%m-%d %R:%S", task.last) or "never" });
100 --self.session.print(require "util.serialization".serialize(task, "debug"));
101 --print("");
102 end
103 end
104 end;
105 });