From: Michael Tremer Date: Fri, 12 Jan 2024 15:46:56 +0000 (+0000) Subject: cron: Refuse running tasks in testing environment X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=776e98e6515d4ad74c95988ed221dc4f9a490796;p=ipfire.org.git cron: Refuse running tasks in testing environment Signed-off-by: Michael Tremer --- diff --git a/src/backend/base.py b/src/backend/base.py index 7e86251a..4af92e27 100644 --- a/src/backend/base.py +++ b/src/backend/base.py @@ -3,6 +3,7 @@ import configparser import io import location +import logging import ssl import tempfile import tornado.httpclient @@ -36,12 +37,16 @@ from .decorators import * DEFAULT_CONFIG = io.StringIO(""" [global] debug = false +environment = testing data_dir = static_dir = %(data_dir)s/static templates_dir = %(data_dir)s/templates """) +# Setup logging +log = logging.getLogger(__name__) + class Backend(object): version = 0 @@ -90,6 +95,13 @@ class Backend(object): return cp + @property + def environment(self): + """ + Returns whether this is running in "production" or "testing" + """ + return self.config.get("global", "environment") + def setup_database(self): """ Sets up the database connection. @@ -159,6 +171,11 @@ class Backend(object): if not func: raise ValueError("Unknown task: %s" % task) + # Check if we are running in production + if not self.environment == "production": + log.warning("Refusing to run task '%s' in '%s' environment" % (task, self.environment)) + return + # Run the task r = await func(*args, **kwargs) diff --git a/src/crontab/ipfire b/src/crontab/ipfire index e44d1394..e93d81da 100644 --- a/src/crontab/ipfire +++ b/src/crontab/ipfire @@ -1,25 +1,25 @@ SHELL=/bin/bash # Update blog feeds once an hour -0 * * * * nobody ipfire.org update-blog-feeds +0 * * * * nobody ipfire.org --logging=error update-blog-feeds # Scan for release files once an hour -0 * * * * nobody ipfire.org scan-files +0 * * * * nobody ipfire.org --logging=error scan-files # Send messages -* * * * * nobody flock /tmp/.ipfire.org.send-all-messages.lock ipfire.org send-all-messages +* * * * * nobody flock /tmp/.ipfire.org.send-all-messages.lock ipfire.org --logging=error send-all-messages # Run campaigns */5 * * * * nobody ipfire.org --logging=error run-campaigns # Announce blog posts -*/5 * * * * nobody flock /tmp/.ipfire.org.announce-blog-posts ipfire.org announce-blog-posts +*/5 * * * * nobody flock /tmp/.ipfire.org.announce-blog-posts ipfire.org --logging=error announce-blog-posts # Cleanup once an hour -30 * * * * nobody ipfire.org cleanup +30 * * * * nobody ipfire.org --logging=error cleanup # Check mirrors once every 30 min */30 * * * * nobody ipfire.org --logging=error check-mirrors # Toot once a day -0 8 * * * nobody sleep ${RANDOM} && ipfire.org toot +0 8 * * * nobody sleep ${RANDOM} && ipfire.org --logging=error toot