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

self.retry in the README example #57

Open
gameveloster opened this issue May 7, 2023 · 3 comments
Open

self.retry in the README example #57

gameveloster opened this issue May 7, 2023 · 3 comments

Comments

@gameveloster
Copy link

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
Copy link

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

@westofpluto
Copy link

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

@dvf
Copy link

dvf commented Oct 2, 2023

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

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

4 participants