-
Notifications
You must be signed in to change notification settings - Fork 0
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 #132 from crypotex/revert-131-revert-130-feature/129
Revert "Revert "Add celery server setup and tasks (feature/129)""
- Loading branch information
Showing
12 changed files
with
188 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import logging | ||
|
||
from celery import shared_task | ||
from django.utils import timezone | ||
|
||
from taas.reservation import models | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task | ||
def remove_expired_reservations(): | ||
limit_date = timezone.now() - timezone.timedelta(minutes=10) | ||
unpaid_reservations = models.Reservation.objects.filter(paid=False, | ||
date_created__lt=limit_date) | ||
if unpaid_reservations.exists(): | ||
unpaid_reservations.delete() | ||
logger.info("Expired unpaid reservations has been removed.") | ||
else: | ||
logger.info("There are no expired unpaid reservations.") | ||
|
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 @@ | ||
from taas.server.celery import app as 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
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,14 @@ | ||
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', 'taas.server.settings') | ||
|
||
app = Celery('taas') | ||
|
||
# Using a string here means the worker will not have to | ||
# pickle the object when using Windows. | ||
app.config_from_object('django.conf:settings') | ||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) |
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
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import logging | ||
|
||
from celery import shared_task | ||
from django.conf import settings | ||
from django.core.mail import send_mail | ||
|
||
from taas.user import models | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task | ||
def email_user_on_registration(user_id): | ||
""" | ||
Sends an email to this user, when he is created. | ||
:param user_id: id of the User | ||
""" | ||
user = models.User.objects.get(id=user_id) | ||
message = settings.USER_REGISTRATION_MESSAGE | ||
message = message % {'first_name': user.first_name} | ||
subject = settings.REGISTRATION_SUBJECT | ||
from_email = settings.EMAIL_HOST_USER | ||
|
||
send_mail(subject, message, from_email, [user.email]) | ||
logger.info('Registration message for user with email %s has been sent.' % user.email) | ||
|
||
|
||
@shared_task | ||
def email_user_on_activation(user_id): | ||
""" | ||
Sends an email to this user, when he is verified. | ||
:param user_id: id of the User | ||
""" | ||
user = models.User.objects.get(id=user_id) | ||
message = settings.USER_VERIFICATION_MESSAGE | ||
message = message % {'first_name': user.first_name} | ||
subject = settings.USER_STATUS_SUBJECT | ||
from_email = settings.EMAIL_HOST_USER | ||
|
||
send_mail(subject, message, from_email, [user.email]) | ||
logger.info('Activation message for user with email %s has been sent.' % user.email) | ||
|
||
|
||
@shared_task | ||
def email_user_on_deactivation(user_id): | ||
""" | ||
Sends an email to this user, when he is disabled. | ||
:param user_id: id of the User | ||
""" | ||
user = models.User.objects.get(id=user_id) | ||
message = settings.USER_DISABLE_MESSAGE | ||
message = message % {'first_name': user.first_name} | ||
subject = settings.USER_STATUS_SUBJECT | ||
from_email = settings.EMAIL_HOST_USER | ||
|
||
send_mail(subject, message, from_email, [user.email]) | ||
logger.info('Deactivation message for user with email %s has been sent.' % user.email) | ||
|
||
|
||
@shared_task | ||
def email_admin_on_user_registration(user_id): | ||
""" | ||
Sends an email to the admin users, when new user was created. | ||
:param user_id: id of the User | ||
""" | ||
user = models.User.objects.get(id=user_id) | ||
message = settings.ADMIN_REGISTRATION_MESSAGE | ||
message = message % {'email': user.email} | ||
subject = settings.REGISTRATION_SUBJECT | ||
from_email = settings.EMAIL_HOST_USER | ||
to_emails = settings.ADMIN_EMAILS | ||
|
||
send_mail(subject, message, from_email, to_emails) | ||
logger.info('User with email %s registration message has been sent to admin emails: %s.' | ||
% (user.email, ', '.join(to_emails))) | ||
|
||
|
||
@shared_task | ||
def email_admin_on_user_deactivation(user_id): | ||
""" | ||
Sends an email to the admin users, when new user was deactivated. | ||
:param user_id: id of the User | ||
""" | ||
|
||
user = models.User.objects.get(id=user_id) | ||
message = settings.ADMIN_USER_DISABLE_MESSAGE | ||
message = message % {'email': user.email} | ||
subject = settings.USER_STATUS_SUBJECT | ||
from_email = settings.EMAIL_HOST_USER | ||
to_emails = settings.ADMIN_EMAILS | ||
|
||
send_mail(subject, message, from_email, to_emails) | ||
logger.info('User with email %s deactivation message has been sent to admin emails: %s.' | ||
% (user.email, ', '.join(to_emails))) |
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