From 3b0600efb61bb0fcffce7d5059ef029a9a3926af Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 15 May 2024 20:41:36 +0000 Subject: [PATCH] feature(jobs): add subscription endpoint --- .../graphql/subscriptions/__init__.py | 0 selfprivacy_api/graphql/subscriptions/jobs.py | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 selfprivacy_api/graphql/subscriptions/__init__.py create mode 100644 selfprivacy_api/graphql/subscriptions/jobs.py diff --git a/selfprivacy_api/graphql/subscriptions/__init__.py b/selfprivacy_api/graphql/subscriptions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/selfprivacy_api/graphql/subscriptions/jobs.py b/selfprivacy_api/graphql/subscriptions/jobs.py new file mode 100644 index 0000000..380badb --- /dev/null +++ b/selfprivacy_api/graphql/subscriptions/jobs.py @@ -0,0 +1,20 @@ +# pylint: disable=too-few-public-methods +import strawberry + +from typing import AsyncGenerator, List + +from selfprivacy_api.jobs import job_notifications + +from selfprivacy_api.graphql.common_types.jobs import ApiJob +from selfprivacy_api.graphql.queries.jobs import get_all_jobs + + +@strawberry.type +class JobSubscriptions: + """Subscriptions related to jobs""" + + @strawberry.subscription + async def job_updates(self) -> AsyncGenerator[List[ApiJob], None]: + # Send the complete list of jobs every time anything gets updated + async for notification in job_notifications(): + yield get_all_jobs()