-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from CodeForBuffalo/async-emails
Add automatic asynchronous emails with Celery and RabbitMQ
- Loading branch information
Showing
31 changed files
with
4,230 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
web: gunicorn affordable_water.wsgi | ||
web: gunicorn affordable_water.wsgi | ||
worker: celery worker --app=affordable_water -l info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
# This will make sure the app is always imported when | ||
# Django starts so that shared_task will use this app. | ||
from .celery import app as celery_app | ||
|
||
__all__ = ('celery_app',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import os | ||
|
||
from celery import Celery | ||
from django.conf import settings | ||
|
||
# set the default Django settings module for the 'celery' program. | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'affordable_water.settings') | ||
|
||
app = Celery('affordable_water', backend='amqp://') | ||
|
||
# Using a string here means the worker doesn't have to serialize | ||
# the configuration object to child processes. | ||
# - namespace='CELERY' means all celery-related configuration keys | ||
# should have a `CELERY_` prefix. | ||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
|
||
# Load task modules from all registered Django app configs. | ||
app.autodiscover_tasks() | ||
|
||
|
||
@app.task(bind=True) | ||
def debug_task(self): | ||
print('Request: {0!r}'.format(self.request)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,14 @@ | |
|
||
DEFAULT_FROM_EMAIL = 'Get Water Wise Buffalo <[email protected]>' | ||
|
||
# Celery Config | ||
CELERY_BROKER_URL = os.getenv('CLOUDAMQP_URL', 'amqp://guest:guest@localhost:5672//') | ||
BROKER_POOL_LIMIT = 1 | ||
CELERY_ACCEPT_CONTENT = ['json'] | ||
CELERY_TASK_SERIALIZER = 'json' | ||
CELERY_RESULT_SERIALIZER = 'json' | ||
CELERY_RESULT_BACKEND = 'rpc' | ||
|
||
# AWS | ||
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID') | ||
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
|
||
class PathwaysConfig(AppConfig): | ||
name = 'pathways' | ||
|
||
def ready(self): | ||
import pathways.signals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
from pathways.tasks import send_email | ||
|
||
class Command(BaseCommand): | ||
help = 'Sends email' | ||
|
||
def handle(self, *args, **kwargs): | ||
if(all(x in kwargs for x in ['subject', 'recipient_list', 'email_template'])): | ||
subject = kwargs['subject'] | ||
recipient_list = kwargs['recipient_list'] | ||
email_template = kwargs['email_template'] | ||
send_email(subject=subject, recipient_list=recipient_list, email_template=email_template) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Generated by Django 2.2.14 on 2020-07-30 19:05 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('pathways', '0010_forgivenessapplication_historicalforgivenessapplication'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='application', | ||
options={'verbose_name': 'Discount Application', 'verbose_name_plural': 'Discount Applications'}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='forgivenessapplication', | ||
options={'verbose_name': 'Amnesty Application', 'verbose_name_plural': 'Amnesty Applications'}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='historicalapplication', | ||
options={'get_latest_by': 'history_date', 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical Discount Application'}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='historicalforgivenessapplication', | ||
options={'get_latest_by': 'history_date', 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical Amnesty Application'}, | ||
), | ||
migrations.AddField( | ||
model_name='forgivenessapplication', | ||
name='notes', | ||
field=models.TextField(blank=True, help_text='Enter any notes for this case'), | ||
), | ||
migrations.AddField( | ||
model_name='forgivenessapplication', | ||
name='status', | ||
field=models.CharField(choices=[('new', 'New'), ('in_progress', 'In Progress'), ('enrolled', 'Enrolled'), ('denied', 'Denied')], default='new', max_length=12), | ||
), | ||
migrations.AddField( | ||
model_name='historicalforgivenessapplication', | ||
name='notes', | ||
field=models.TextField(blank=True, help_text='Enter any notes for this case'), | ||
), | ||
migrations.AddField( | ||
model_name='historicalforgivenessapplication', | ||
name='status', | ||
field=models.CharField(choices=[('new', 'New'), ('in_progress', 'In Progress'), ('enrolled', 'Enrolled'), ('denied', 'Denied')], default='new', max_length=12), | ||
), | ||
] |
46 changes: 46 additions & 0 deletions
46
pathways/migrations/0011_emailcommunication_historicalemailcommunication.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Generated by Django 2.2.14 on 2020-07-14 19:36 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import simple_history.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('pathways', '0010_forgivenessapplication_historicalforgivenessapplication'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='EmailCommunication', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('email_address', models.EmailField(max_length=254)), | ||
('discount_application_received', models.BooleanField(default=False)), | ||
('amnesty_application_received', models.BooleanField(default=False)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='HistoricalEmailCommunication', | ||
fields=[ | ||
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), | ||
('email_address', models.EmailField(max_length=254)), | ||
('discount_application_received', models.BooleanField(default=False)), | ||
('amnesty_application_received', models.BooleanField(default=False)), | ||
('history_id', models.AutoField(primary_key=True, serialize=False)), | ||
('history_date', models.DateTimeField()), | ||
('history_change_reason', models.CharField(max_length=100, null=True)), | ||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), | ||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'verbose_name': 'historical email communication', | ||
'ordering': ('-history_date', '-history_id'), | ||
'get_latest_by': 'history_date', | ||
}, | ||
bases=(simple_history.models.HistoricalChanges, models.Model), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 2.2.14 on 2020-07-16 19:19 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('pathways', '0011_emailcommunication_historicalemailcommunication'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='emailcommunication', | ||
name='id', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicalemailcommunication', | ||
name='id', | ||
), | ||
migrations.AlterField( | ||
model_name='emailcommunication', | ||
name='email_address', | ||
field=models.EmailField(editable=False, max_length=254, primary_key=True, serialize=False), | ||
), | ||
migrations.AlterField( | ||
model_name='historicalemailcommunication', | ||
name='email_address', | ||
field=models.EmailField(db_index=True, editable=False, max_length=254), | ||
), | ||
] |
Oops, something went wrong.