diff --git a/background-jobs/app/demo.py b/background-jobs/app/demo.py new file mode 100644 index 00000000..a89e6dd0 --- /dev/null +++ b/background-jobs/app/demo.py @@ -0,0 +1,16 @@ +import sys +import time + + +def main() -> None: + seconds = int(sys.argv[1]) if len(sys.argv) > 1 else 20 + print(f"Demo job started, running for {seconds} seconds.", flush=True) + for elapsed in range(1, seconds + 1): + time.sleep(1) + if elapsed % 5 == 0: + print(f"Progress: {elapsed}/{seconds} seconds.", flush=True) + print("Demo job finished successfully.", flush=True) + + +if __name__ == "__main__": + main() diff --git a/background-jobs/entrypoint.sh b/background-jobs/entrypoint.sh index 4cfaa044..10b790e1 100644 --- a/background-jobs/entrypoint.sh +++ b/background-jobs/entrypoint.sh @@ -14,12 +14,21 @@ case "$JOB" in # Print counts for the aktuell / aktuell_postproc indices (read-only). exec python sync.py --stats ;; + demo-a) + exec python demo.py 20 + ;; + demo-b) + exec python demo.py 25 + ;; + demo-c) + exec python demo.py 30 + ;; "") - echo "No job given. Available jobs: news, news-stats" >&2 + echo "No job given. Available jobs: news, news-stats, demo-a, demo-b, demo-c" >&2 exit 2 ;; *) - echo "Unknown job: $JOB. Available jobs: news, news-stats" >&2 + echo "Unknown job: $JOB. Available jobs: news, news-stats, demo-a, demo-b, demo-c" >&2 exit 2 ;; esac diff --git a/service/src/main/inse/background_jobs/model.py b/service/src/main/inse/background_jobs/model.py index 7d470890..cb46d07d 100644 --- a/service/src/main/inse/background_jobs/model.py +++ b/service/src/main/inse/background_jobs/model.py @@ -13,6 +13,9 @@ from sqlmodel import Field, SQLModel class BackgroundJobName(StrEnum): NEWS = "news" NEWS_STATS = "news-stats" + DEMO_A = "demo-a" + DEMO_B = "demo-b" + DEMO_C = "demo-c" class JobRunStatus(StrEnum): diff --git a/service/src/main/inse/background_jobs/seed.py b/service/src/main/inse/background_jobs/seed.py index 6a4a42d9..3ced610e 100644 --- a/service/src/main/inse/background_jobs/seed.py +++ b/service/src/main/inse/background_jobs/seed.py @@ -33,6 +33,39 @@ PREDEFINED_JOB_DEFINITIONS: list[dict] = [ "schedule": None, "enabled": True, }, + { + "name": "Demo-Job A", + "description": ( + "Testjob für Demos: läuft ca. 20 Sekunden, schreibt Fortschritt " + "ins Log und verändert nichts." + ), + "target_index": "-", + "job": BackgroundJobName.DEMO_A, + "schedule": None, + "enabled": True, + }, + { + "name": "Demo-Job B", + "description": ( + "Testjob für Demos: läuft ca. 25 Sekunden, schreibt Fortschritt " + "ins Log und verändert nichts." + ), + "target_index": "-", + "job": BackgroundJobName.DEMO_B, + "schedule": None, + "enabled": True, + }, + { + "name": "Demo-Job C", + "description": ( + "Testjob für Demos: läuft ca. 30 Sekunden, schreibt Fortschritt " + "ins Log und verändert nichts." + ), + "target_index": "-", + "job": BackgroundJobName.DEMO_C, + "schedule": None, + "enabled": True, + }, ] diff --git a/webapp/src/app/api/model/backgroundJobName.ts b/webapp/src/app/api/model/backgroundJobName.ts index 2c65eba1..0a0f4555 100644 --- a/webapp/src/app/api/model/backgroundJobName.ts +++ b/webapp/src/app/api/model/backgroundJobName.ts @@ -8,12 +8,12 @@ * Do not edit the class manually. */ -/** - * Jobs known to the background-jobs image\'s entrypoint.sh dispatcher. - */ export const BackgroundJobName = { News: 'news', NewsStats: 'news-stats', + DemoA: 'demo-a', + DemoB: 'demo-b', + DemoC: 'demo-c', } as const; export type BackgroundJobName = (typeof BackgroundJobName)[keyof typeof BackgroundJobName];