mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-28 06:51:28 +00:00
Fix
This commit is contained in:
parent
d8d3cd2068
commit
8ea0d89d71
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import datetime
|
||||
from typing import AsyncGenerator
|
||||
import typing
|
||||
|
||||
|
@ -7,10 +8,23 @@ from selfprivacy_api.graphql import IsAuthenticated
|
|||
|
||||
from selfprivacy_api.jobs import Job, Jobs
|
||||
|
||||
@strawberry.type
|
||||
class ApiJob:
|
||||
name: str
|
||||
description: str
|
||||
status: str
|
||||
status_text: typing.Optional[str]
|
||||
progress: typing.Optional[int]
|
||||
created_at: datetime.datetime
|
||||
updated_at: datetime.datetime
|
||||
finished_at: typing.Optional[datetime.datetime]
|
||||
error: typing.Optional[str]
|
||||
result: typing.Optional[str]
|
||||
|
||||
@strawberry.type
|
||||
class JobSubscription:
|
||||
@strawberry.subscription(permission_classes=[IsAuthenticated])
|
||||
async def job_subscription(self) -> AsyncGenerator[typing.List[Job], None]:
|
||||
async def job_subscription(self) -> AsyncGenerator[typing.List[ApiJob], None]:
|
||||
is_updated = True
|
||||
def callback(jobs: typing.List[Job]):
|
||||
nonlocal is_updated
|
||||
|
@ -20,7 +34,18 @@ class JobSubscription:
|
|||
while True:
|
||||
if is_updated:
|
||||
is_updated = False
|
||||
yield Jobs().jobs
|
||||
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() ]
|
||||
except GeneratorExit:
|
||||
Jobs().remove_observer(callback)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue