expo-community / expo-server-sdk-python

Exponent Server SDK
MIT License
143 stars 42 forks source link

self.retry in the README example #57

Open gameveloster opened 1 year ago

gameveloster commented 1 year ago

In the example in the README, the code has two occurance of:

        raise self.retry(exc=exc)

Where is the retry method defined in the example, and why is it using self.retry when it is not called from inside a class method?

andresti commented 1 year ago

Also there is an import: from notifications.models import PushToken What is this notifications models that is being imported?

westofpluto commented 1 year ago

We would appreciate it if the author answered the question on where self.retry comes from

dvf commented 11 months ago

This looks like it was lifted from a Celery task.

Typically, you want to send push notifications in the background, and Celery is a tool for background tasks. You gain access to the self keyword from the Celery decorator, which would look something like this:

@app.task(
    bind=True,
    max_retries=5,
    default_retry_delay=10,
    ignore_result=True,
)
def send_push_message(self, token, message, extra=None):
    ...
    if error:
        self.retry(...)

When the task fails, you can use self.retry(...) to reschedule it. Here are the docs: https://docs.celeryq.dev/en/stable/index.html

bind=True provides the self parameter which gives you access to the task's meta info. Here are the docs: https://docs.celeryq.dev/en/stable/userguide/tasks.html#bound-tasks