mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 04:51:27 +00:00
Trying out
This commit is contained in:
parent
8f940e64fd
commit
b965ffd96a
|
@ -8,6 +8,7 @@ from selfprivacy_api.graphql import IsAuthenticated
|
||||||
|
|
||||||
from selfprivacy_api.jobs import Job, Jobs
|
from selfprivacy_api.jobs import Job, Jobs
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class ApiJob:
|
class ApiJob:
|
||||||
name: str
|
name: str
|
||||||
|
@ -21,19 +22,21 @@ class ApiJob:
|
||||||
error: typing.Optional[str]
|
error: typing.Optional[str]
|
||||||
result: typing.Optional[str]
|
result: typing.Optional[str]
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class JobSubscription:
|
class JobSubscription:
|
||||||
@strawberry.subscription()
|
@strawberry.subscription()
|
||||||
async def job_subscription(self) -> AsyncGenerator[typing.List[ApiJob], None]:
|
async def job_subscription(self) -> AsyncGenerator[typing.List[ApiJob], None]:
|
||||||
is_updated = True
|
is_updated = True
|
||||||
|
|
||||||
def callback(jobs: typing.List[Job]):
|
def callback(jobs: typing.List[Job]):
|
||||||
nonlocal is_updated
|
nonlocal is_updated
|
||||||
is_updated = True
|
is_updated = True
|
||||||
|
|
||||||
|
print("Subscribing to job updates...")
|
||||||
Jobs().add_observer(callback)
|
Jobs().add_observer(callback)
|
||||||
while True:
|
yield [
|
||||||
if is_updated:
|
ApiJob(
|
||||||
is_updated = False
|
|
||||||
yield [ ApiJob(
|
|
||||||
name=job.name,
|
name=job.name,
|
||||||
description=job.description,
|
description=job.description,
|
||||||
status=job.status.name,
|
status=job.status.name,
|
||||||
|
@ -44,4 +47,24 @@ class JobSubscription:
|
||||||
finished_at=job.finished_at,
|
finished_at=job.finished_at,
|
||||||
error=job.error,
|
error=job.error,
|
||||||
result=job.result,
|
result=job.result,
|
||||||
) for job in Jobs().get_jobs() ]
|
)
|
||||||
|
for job in Jobs().get_jobs()
|
||||||
|
]
|
||||||
|
while True:
|
||||||
|
if is_updated:
|
||||||
|
is_updated = False
|
||||||
|
yield [
|
||||||
|
ApiJob(
|
||||||
|
name=job.name,
|
||||||
|
description=job.description,
|
||||||
|
status=job.status.name,
|
||||||
|
status_text=job.status_text,
|
||||||
|
progress=job.progress,
|
||||||
|
created_at=job.created_at,
|
||||||
|
updated_at=job.updated_at,
|
||||||
|
finished_at=job.finished_at,
|
||||||
|
error=job.error,
|
||||||
|
result=job.result,
|
||||||
|
)
|
||||||
|
for job in Jobs().get_jobs()
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in a new issue