mukesh
mukesh

Reputation: 716

Celery : Execute task after a specific time gap

I want to send an email to my users exactly 48 hours after they have registered.How do i achieve this using celery? If I create a periodic task to send an email, I will have to decide a specific time during which i want to execute that task. I don't want to keep run a celery task every second to check if there are any emails needed to be sent.

Upvotes: 20

Views: 6607

Answers (1)

schillingt
schillingt

Reputation: 13731

You'll want to make use of ETA. Read that section of the docs as it'll have more information. However, your code will look something like this:

from datetime import datetime, timedelta
send_date = datetime.utcnow() + timedelta(days=2)
email_user.apply_async([user], eta=send_date)

Upvotes: 40

Related Questions