diff options
| author | Daniel Schadt <kingdread@gmx.de> | 2026-10-08 19:20:43 +0200 |
|---|---|---|
| committer | Daniel Schadt <kingdread@gmx.de> | 2026-10-08 19:20:43 +0200 |
| commit | c1b6c50bba7564b1a5d099aadb062161badaba19 (patch) | |
| tree | f3034d052936fe5cfee8003cfd63a4ada5f2b100 /container/cron.py | |
| parent | 930f961259136a2b3d52db98873f93baea27a81b (diff) | |
| parent | 31e1971c64aafa78ff55033ff1ceb4169e41d574 (diff) | |
| download | fietsboek-c1b6c50bba7564b1a5d099aadb062161badaba19.tar.gz fietsboek-c1b6c50bba7564b1a5d099aadb062161badaba19.tar.bz2 fietsboek-c1b6c50bba7564b1a5d099aadb062161badaba19.zip | |
Merge branch 'climbs'
Diffstat (limited to 'container/cron.py')
| -rw-r--r-- | container/cron.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/container/cron.py b/container/cron.py new file mode 100644 index 0000000..47aeaa9 --- /dev/null +++ b/container/cron.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import os +import sys +import datetime +import subprocess +import time + +SLEEPY_TIME = datetime.timedelta(hours=1) +SLEEPY_BATCH = datetime.timedelta(minutes=10) +LOGFILE = "/fietsboek/fietscron.log" + +pid = os.fork() +if pid > 0: + sys.exit(0) + +os.setsid() + +pid = os.fork() +if pid > 0: + sys.exit(0) + + +def run_fietscron(): + with open(LOGFILE, "wb") as stdout: + subprocess.run( + ["/usr/local/bin/fietscron", "-c", "/fietsboek/fietsboek.ini"], + stdout=stdout, + stderr=subprocess.STDOUT, + ) + + +def wait(start): + wanted_time = start + SLEEPY_TIME + while (now := datetime.datetime.now(tz=datetime.UTC)) < wanted_time: + to_sleep = min(wanted_time - now, SLEEPY_BATCH) + time.sleep(to_sleep.total_seconds()) + + +while True: + start = datetime.datetime.now(tz=datetime.UTC) + run_fietscron() + wait(start) |
