mod_cron: Add a 'weekly' job frequency
authorKim Alvefur <zash@zash.se>
Fri, 03 Dec 2021 09:05:41 +0100
changeset 12006 cbed7d8d8f35
parent 12005 5a8c6f9a4583
child 12007 121c0401f83e
mod_cron: Add a 'weekly' job frequency
.luacheckrc
core/moduleapi.lua
plugins/mod_cron.lua
teal-src/plugins/mod_cron.tl
--- a/.luacheckrc	Fri Dec 03 09:01:09 2021 +0100
+++ b/.luacheckrc	Fri Dec 03 09:05:41 2021 +0100
@@ -52,6 +52,7 @@
 		"module.add_identity",
 		"module.add_item",
 		"module.add_timer",
+		"module.weekly",
 		"module.daily",
 		"module.hourly",
 		"module.broadcast",
--- a/core/moduleapi.lua	Fri Dec 03 09:01:09 2021 +0100
+++ b/core/moduleapi.lua	Fri Dec 03 09:05:41 2021 +0100
@@ -521,6 +521,11 @@
 	self:cron({ name = name; when = "daily"; run = fun });
 end
 
+function api:weekly(name, fun)
+	if type(name) == "function" then fun, name = name, nil; end
+	self:cron({ name = name; when = "weekly"; run = fun });
+end
+
 local path_sep = package.config:sub(1,1);
 function api:get_directory()
 	return self.resource_path or self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil;
--- a/plugins/mod_cron.lua	Fri Dec 03 09:01:09 2021 +0100
+++ b/plugins/mod_cron.lua	Fri Dec 03 09:05:41 2021 +0100
@@ -3,7 +3,7 @@
 local async = require("util.async");
 local datetime = require("util.datetime");
 
-local periods = { hourly = 3600; daily = 86400 }
+local periods = { hourly = 3600; daily = 86400; weekly = 7 * 86400 }
 
 local active_hosts = {}
 
--- a/teal-src/plugins/mod_cron.tl	Fri Dec 03 09:01:09 2021 +0100
+++ b/teal-src/plugins/mod_cron.tl	Fri Dec 03 09:05:41 2021 +0100
@@ -12,6 +12,7 @@
 local enum frequency
 	"hourly"
 	"daily"
+	"weekly"
 end
 
 local record task_spec
@@ -28,7 +29,7 @@
 	item : task_spec
 end
 
-local periods : { frequency : integer } = { hourly = 3600, daily = 86400 }
+local periods : { frequency : integer } = { hourly = 3600, daily = 86400, weekly = 7*86400 }
 
 local active_hosts : { string : boolean } = {  }