Skip to content

Commit 107012a

Browse files
committed
feat: easier way to define timers
1 parent 844065d commit 107012a

14 files changed

+324
-36
lines changed

systemd/generate-timers.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
3+
from os import mkdir
4+
from shutil import rmtree
5+
from tomllib import loads
6+
7+
from jinja2 import Environment, FileSystemLoader
8+
9+
if __name__ == "__main__":
10+
with open("./timers.toml", "r") as f:
11+
timers = loads(f.read())["timer"]
12+
if not timers:
13+
exit()
14+
env = Environment(loader=FileSystemLoader("./templates"))
15+
templates = {
16+
"service": env.get_template("service"),
17+
"timer": env.get_template("timer"),
18+
}
19+
rmtree("output")
20+
mkdir("output")
21+
for timer in timers:
22+
base_path = "./output/outdated-" + timer["command"]
23+
for type in ["service", "timer"]:
24+
with open(f"{base_path}.{type}", "w") as f:
25+
f.write(templates[type].render(**timer))

systemd/notifications.service

-9
This file was deleted.

systemd/notifications.timer

-9
This file was deleted.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Notify maintainers about their projects if necessary
3+
Wants=outdated-notify.timer
4+
5+
[Service]
6+
ExecStart=docker exec outdated-api sh -c './manage.py notify'
7+
8+
[Install]
9+
WantedBy=multi-user.target

systemd/output/outdated-notify.timer

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Timer for Notify maintainers about their projects if necessary
3+
4+
[Timer]
5+
Unit=outdated-notify.service
6+
OnCalendar=Mon *-*-* 00:00:00
7+
8+
[Install]
9+
WantedBy=timers.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Sync all projects with their remote counterparts
3+
Wants=outdated-syncprojects.timer
4+
5+
[Service]
6+
ExecStart=docker exec outdated-api sh -c './manage.py syncprojects'
7+
8+
[Install]
9+
WantedBy=multi-user.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Timer for Sync all projects with their remote counterparts
3+
4+
[Timer]
5+
Unit=outdated-syncprojects.service
6+
OnCalendar=*-*-* 00:00:00
7+
8+
[Install]
9+
WantedBy=timers.target

systemd/poetry.lock

+216
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

systemd/pyproject.toml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[tool.poetry]
2+
name = "systemd-timer-creation-tool"
3+
version = "0.1.0"
4+
description = "create systemd timers without boilerplate"
5+
authors = ["Adfinis AG"]
6+
readme = "README.md"
7+
packages = [{include = "systemd_timer_creation_tool"}]
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.11"
11+
jinja2 = "^3.1.2"
12+
13+
14+
[tool.poetry.group.dev.dependencies]
15+
black = "^23.7.0"
16+
isort = "^5.12.0"
17+
18+
[build-system]
19+
requires = ["poetry-core"]
20+
build-backend = "poetry.core.masonry.api"

systemd/syncprojects.service

-9
This file was deleted.

systemd/syncprojects.timer

-9
This file was deleted.

systemd/templates/service

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description={{description}}
3+
Wants=outdated-{{command}}.timer
4+
5+
[Service]
6+
ExecStart=docker exec outdated-api sh -c './manage.py {{command}}'
7+
8+
[Install]
9+
WantedBy=multi-user.target

systemd/templates/timer

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Timer for {{description}}
3+
4+
[Timer]
5+
Unit=outdated-{{command}}.service
6+
OnCalendar={{schedule}}
7+
8+
[Install]
9+
WantedBy=timers.target

systemd/timers.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[[timer]]
2+
description="Sync all projects with their remote counterparts"
3+
command="syncprojects"
4+
schedule="*-*-* 00:00:00"
5+
6+
[[timer]]
7+
description="Notify maintainers about their projects if necessary"
8+
command="notify"
9+
schedule="Mon *-*-* 00:00:00"

0 commit comments

Comments
 (0)