Skip to content

Commit

Permalink
Merge pull request #6 from AbhishekPednekar84/celery-redis-int
Browse files Browse the repository at this point in the history
Celery redis int
  • Loading branch information
AbhishekPednekar84 committed Jan 1, 2020
2 parents c9d884a + 93d4f48 commit eb19cea
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
9 changes: 9 additions & 0 deletions celery_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import Flask
from utilities.factory import make_celery


def create_celery_app():
app = Flask(__name__)
celery = make_celery(app)

return celery
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Config:
SQLALCHEMY_DATABASE_URI = os.getenv("SQLALCHEMY_DATABASE_URI")
SQLALCHEMY_TRACK_MODIFICATIONS = True
RESTPLUS_MASK_SWAGGER = False
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL")


class TestConfig(Config):
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
alembic==1.3.1
amqp==2.5.2
aniso8601==8.0.0
aspy.yaml==1.3.0
atomicwrites==1.3.0
attrs==19.1.0
autopep8==1.4.4
billiard==3.6.1.0
blinker==1.4
celery==4.4.0
cfgv==2.0.1
Click==7.0
colorama==0.4.1
Expand All @@ -19,6 +22,7 @@ importlib-metadata==0.19
itsdangerous==1.1.0
Jinja2==2.10.1
jsonschema==3.2.0
kombu==4.6.7
Mako==1.1.0
MarkupSafe==1.1.1
more-itertools==7.2.0
Expand All @@ -40,9 +44,11 @@ python-dotenv==0.10.3
python-editor==1.0.4
pytz==2019.3
PyYAML==5.1.2
redis==3.3.11
six==1.12.0
SQLAlchemy==1.3.10
toml==0.10.0
vine==1.3.0
virtualenv==16.7.7
wcwidth==0.1.7
Werkzeug==0.15.5
Expand Down
22 changes: 22 additions & 0 deletions utilities/factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import config
from celery import Celery

# from app import create_app


def make_celery(app):
# app = app or create_app()
celery = Celery(app.import_name, broker=config.Config.CELERY_BROKER_URL)
celery.conf.update(app.config)

TaskBase = celery.Task

class ContextTask(TaskBase):
abstract = True

def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)

celery.Task = ContextTask
return celery
4 changes: 4 additions & 0 deletions utilities/send_email.py → utilities/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import smtplib
import ssl
from email.message import EmailMessage
from celery_app import create_celery_app

celery = create_celery_app()


@celery.task
def send_email(caller_name, caller_email, caller_subject, caller_message):
sender_email = os.getenv("EMAIL_USER")
password = os.environ.get("EMAIL_PASS")
Expand Down
4 changes: 2 additions & 2 deletions views/contact.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, flash, redirect, url_for, render_template
from forms.contact import ContactForm
from utilities.send_email import send_email
from utilities.tasks import send_email

contact_blueprint = Blueprint("contact", __name__, template_folder="templates")

Expand All @@ -9,7 +9,7 @@
def contact():
form = ContactForm()
if form.validate_on_submit():
send_email(
send_email.delay(
form.username.data,
form.email.data,
form.subject.data,
Expand Down

0 comments on commit eb19cea

Please sign in to comment.