Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples #101

Open
NixBiks opened this issue Jan 3, 2023 · 0 comments
Open

Add examples #101

NixBiks opened this issue Jan 3, 2023 · 0 comments

Comments

@NixBiks
Copy link

NixBiks commented Jan 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant