expo-server-sdk-python icon indicating copy to clipboard operation
expo-server-sdk-python copied to clipboard

self.retry in the README example

Open gameveloster opened this issue 2 years ago • 3 comments

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?

gameveloster avatar May 07 '23 23:05 gameveloster

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

andresti avatar May 22 '23 14:05 andresti

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

westofpluto avatar Aug 03 '23 19:08 westofpluto

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

dvf avatar Oct 02 '23 20:10 dvf