Changeset

12002:cbed7d8d8f35

mod_cron: Add a 'weekly' job frequency
author Kim Alvefur <zash@zash.se>
date Fri, 03 Dec 2021 09:05:41 +0100
parents 12001:5a8c6f9a4583
children 12003:121c0401f83e
files .luacheckrc core/moduleapi.lua plugins/mod_cron.lua teal-src/plugins/mod_cron.tl
diffstat 4 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 } = {  }