Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added systemd timers for notifications and syncing #39

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
api:
build: ./api
user: "${UID:?Set UID env variable to your user id}"
container_name: "outdated-api"
depends_on:
- db
ember:
Expand Down
25 changes: 25 additions & 0 deletions systemd/generate-timers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

from os import mkdir
from shutil import rmtree
from tomllib import loads

from jinja2 import Environment, FileSystemLoader

if __name__ == "__main__":
with open("./timers.toml", "r") as f:
timers = loads(f.read())["timer"]
if not timers:
exit()
env = Environment(loader=FileSystemLoader("./templates"))
templates = {
"service": env.get_template("service"),
"timer": env.get_template("timer"),
}
rmtree("output")
mkdir("output")
for timer in timers:
base_path = "./output/outdated-" + timer["command"]
for type in ["service", "timer"]:
with open(f"{base_path}.{type}", "w") as f:
f.write(templates[type].render(**timer))
9 changes: 9 additions & 0 deletions systemd/output/outdated-notify.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Notify maintainers about their projects if necessary
Wants=outdated-notify.timer

[Service]
ExecStart=docker exec outdated-api sh -c './manage.py notify'

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions systemd/output/outdated-notify.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Timer for Notify maintainers about their projects if necessary

[Timer]
Unit=outdated-notify.service
OnCalendar=Mon *-*-* 00:00:00

[Install]
WantedBy=timers.target
9 changes: 9 additions & 0 deletions systemd/output/outdated-syncprojects.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Sync all projects with their remote counterparts
Wants=outdated-syncprojects.timer

[Service]
ExecStart=docker exec outdated-api sh -c './manage.py syncprojects'

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions systemd/output/outdated-syncprojects.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Timer for Sync all projects with their remote counterparts

[Timer]
Unit=outdated-syncprojects.service
OnCalendar=*-*-* 00:00:00

[Install]
WantedBy=timers.target
216 changes: 216 additions & 0 deletions systemd/poetry.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions systemd/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "systemd-timer-creation-tool"
version = "0.1.0"
description = "create systemd timers without boilerplate"
authors = ["Adfinis AG"]
readme = "README.md"
packages = [{include = "systemd_timer_creation_tool"}]

[tool.poetry.dependencies]
python = "^3.11"
jinja2 = "^3.1.2"


[tool.poetry.group.dev.dependencies]
black = "^23.7.0"
isort = "^5.12.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
9 changes: 9 additions & 0 deletions systemd/templates/service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description={{description}}
Wants=outdated-{{command}}.timer

[Service]
ExecStart=docker exec outdated-api sh -c './manage.py {{command}}'

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions systemd/templates/timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Timer for {{description}}

[Timer]
Unit=outdated-{{command}}.service
OnCalendar={{schedule}}

[Install]
WantedBy=timers.target
9 changes: 9 additions & 0 deletions systemd/timers.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[timer]]
description="Sync all projects with their remote counterparts"
command="syncprojects"
schedule="*-*-* 00:00:00"

[[timer]]
description="Notify maintainers about their projects if necessary"
command="notify"
schedule="Mon *-*-* 00:00:00"