celery-types
celery-types copied to clipboard
Add examples
Hi,
It would be great with some examples for both server and client side code (client with no access to server implementation, i.e. defined via celery.signature
).
Currently I'm doing something like this client side
from celery import Signature, Celery
class WorkerClient(object):
def __init__(self):
self.app = Celery()
def handle_request(self, a: int, b: int, task_id=None):
sig: Signature[int] = self.app.signature("handle_request")
options = {}
if task_id:
options["task_id"] = task_id
return sig.apply_async(kwargs=dict(a=a, b=b), **options)
But it's not that typesafe on inputs (just settings kwargs). Preferably I'd define the signature with something like this where both input and return type are given.
HandleRequest = Task[[int, int], int]
sig: Sig[HandleRequest] = self.app.signature("handle_request")
Not sure if it's possible or if there are any good indicators on how to type client side code