]> git.ipfire.org Git - ipfire.org.git/commitdiff
cron: Refuse running tasks in testing environment
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Jan 2024 15:46:56 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 12 Jan 2024 15:46:56 +0000 (15:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/base.py
src/crontab/ipfire

index 7e86251aa86553c63a43cf7511bede17af930635..4af92e275728ee3c607e2186f03ba2fe261a6e2e 100644 (file)
@@ -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)
 
index e44d13941afd78b349a6634f527ec4ad0d5160a8..e93d81da3580752fc5e1e6f65fbc8f95642f3aa7 100644 (file)
@@ -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