# HG changeset patch # User Matthew Wild # Date 1701344339 0 # Node ID 6f9b15757384f880f33d46728a008a7816e0546a # Parent 2738dda885bba6b4e308a16b55d0a657d63992e8 mod_cron: Add shell command to list registered cron tasks with status diff -r 2738dda885bb -r 6f9b15757384 plugins/mod_cron.lua --- a/plugins/mod_cron.lua Thu Nov 30 11:22:40 2023 +0000 +++ b/plugins/mod_cron.lua Thu Nov 30 11:38:59 2023 +0000 @@ -75,3 +75,31 @@ module:log("debug", "Wait %ds", delay); return delay end); + +module:add_item("shell-command", { + section = "cron"; + section_desc = "View and manage recurring tasks"; + name = "tasks"; + desc = "View registered tasks"; + args = {}; + handler = function (self, host) + local format_table = require "prosody.util.human.io".table; + local it = require "util.iterators"; + local row = format_table({ + { title = "Host", width = "2p" }; + { title = "Task", width = "3p" }; + { title = "Desc", width = "3p" }; + { title = "When", width = "1p" }; + { title = "Last run", width = "20" }; + }, self.session.width); + local print = self.session.print; + print(row()); + for host in it.sorted_pairs(host and { [host]=true } or active_hosts) do + for _, task in ipairs(module:context(host):get_host_items("task")) do + print(row { host, task.id, task.name, task.when, task.last and os.date("%Y-%m-%d %R:%S", task.last) or "never" }); + --self.session.print(require "util.serialization".serialize(task, "debug")); + --print(""); + end + end + end; +});