pypi / warehouse

The Python Package Index
https://pypi.org
Apache License 2.0
3.58k stars 965 forks source link

Configure send_mail. #1272

Closed gsb-eng closed 8 years ago

gsb-eng commented 8 years ago

Warehouse doesn't have any send_mail functionality configured, Sending mail is necessary for functionalities like password recovery, user registration confirmation, etc.

Initial thoughts:

gsb-eng commented 8 years ago

@dstufft : Could you please add if anything else needs to be considered?

gsb-eng commented 8 years ago

I'll be working on this.

gsb-eng commented 8 years ago

Broadly we can categorize warehouse email requirement into two types.

1) Instant Emails:

Use Cases : Password recovery, registration confirmation, alert when a new maintainer or author added, etc. I think 100% of emails goes through PyPi comes under this category.

Implementation: We can use a celery task to send email asynchronously, Worker should be always running to handle queued tasks.

Handling Failures: If any exception occurs in the first attempt, we've to handle two cases here.

  1. retry = True: We'll try re-sending for 3 to 4 times (consensus required) and give up after that.
  2. retry = False: Give up.

Sample celery task:

@app.task(bind=True,
def send_mail(task, retry=True, max_retries=3):
     try:
         mailer.send_immediately(message)
    except Exception, exc:
        if retry:
            task.retry(countdown=1, max_retries=max_retries, exc=exc)
        raise

2) Scheduled Emails:

Use Cases: News letters, some mass updates, etc.

Implementation: We can use a celery task to send email asynchronously, Worker should run at defined time to handle the queued tasks.

Handling Failures: We can maintain a different queue for the failed tasks and a worker should be running always to handle the failure queue.

Sample celery task:

@app.task(bind=True)
def send_email(task):
     try:
         mailer.send(message)
    except Exception, exc:
        send_email(args, queue='failure_queue')

Consensus required on below queries:

  1. Do we really need scheduled emails?
  2. If a instant email fails, how many times we've to try re-send the email?
gsb-eng commented 8 years ago

@dstufft : Can I close this issue now?