mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-24 13:01:28 +00:00
uh
This commit is contained in:
parent
8ea0d89d71
commit
8f940e64fd
|
@ -23,29 +23,25 @@ class ApiJob:
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class JobSubscription:
|
class JobSubscription:
|
||||||
@strawberry.subscription(permission_classes=[IsAuthenticated])
|
@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
|
||||||
Jobs().add_observer(callback)
|
Jobs().add_observer(callback)
|
||||||
try:
|
while True:
|
||||||
while True:
|
if is_updated:
|
||||||
if is_updated:
|
is_updated = False
|
||||||
is_updated = False
|
yield [ ApiJob(
|
||||||
yield [ ApiJob(
|
name=job.name,
|
||||||
name=job.name,
|
description=job.description,
|
||||||
description=job.description,
|
status=job.status.name,
|
||||||
status=job.status.name,
|
status_text=job.status_text,
|
||||||
status_text=job.status_text,
|
progress=job.progress,
|
||||||
progress=job.progress,
|
created_at=job.created_at,
|
||||||
created_at=job.created_at,
|
updated_at=job.updated_at,
|
||||||
updated_at=job.updated_at,
|
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() ]
|
|
||||||
except GeneratorExit:
|
|
||||||
Jobs().remove_observer(callback)
|
|
||||||
return
|
|
||||||
|
|
Loading…
Reference in a new issue