I am building a progress bar application that uses celery for executing async tasks. The task is started with a GraphQL mutation and updates its own state each second:
@celery.task(bind=True, name='mock_analyzing')
def mock_analyzing(self, up_to=20):
for i in range(up_to):
self.update_state(
state='PROGRESS',
meta={
'done': i,
'total': up_to
}
)
time.sleep(1)
return 'SUCCESS'
When I want to publish that state with a GraphQL subscription, the attributes aren't set correctly. What am I doing wrong?
class Subscription(graphene.ObjectType):
file_status = graphene.String(file_id=graphene.ID())
def resolve_file_status(root, info, file_id):
task = mock_analyzing.AsyncResult(file_id)
return Observable.interval(1000)\
.map(lambda done = task.info.get('done'), total = task.info.get('total'): {id: file_id, 'done': done, 'total': total})\
.take_while(lambda i: not task.ready())
I think I didnt understand the Observable right. Can someone help me? Thanks in advance