forked from awesto/django-shop
-
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 branch 'drafts/async-worker' into releases/0.12.x
- Loading branch information
Showing
9 changed files
with
101 additions
and
26 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
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 was deleted.
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
import redis | ||
import schedule | ||
import time | ||
|
||
|
||
if __name__ == '__main__': | ||
from django import setup | ||
from django.conf import settings | ||
from django.core.management import call_command | ||
from django.utils import timezone | ||
|
||
# initialize Django | ||
setup() | ||
|
||
# schedule jobs | ||
schedule.every().minute.do(call_command, 'send_queued_mail') | ||
rebuild_at = timezone.now() + timezone.timedelta(minutes=6) | ||
schedule.every().hour.at(rebuild_at.strftime('*:%M')).do(call_command, 'rebuild_index', interactive=False) | ||
schedule.every().sunday.do(call_command, 'shopcustomers', delete_expired=True) | ||
|
||
if hasattr(settings, 'SESSION_REDIS'): | ||
redis_con = dict((key, settings.SESSION_REDIS[key]) for key in ['host', 'port', 'db', 'socket_timeout']) | ||
pool = redis.ConnectionPool(**redis_con) | ||
r = redis.Redis(connection_pool=pool) | ||
pubsub = r.pubsub() | ||
pubsub.subscribe('django-SHOP') | ||
else: | ||
pubsub = type('PubSub', (), {'get_message': lambda s: None})() | ||
|
||
while True: | ||
message = pubsub.get_message() | ||
if message: | ||
if message['data'] == 'send_queued_mail': | ||
call_command('send_queued_mail') | ||
schedule.run_pending() | ||
time.sleep(1) |
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 |
---|---|---|
@@ -1,7 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
try: | ||
import redis | ||
except ImportError: | ||
redis = None | ||
from django.conf import settings | ||
from django.dispatch import Signal | ||
|
||
|
||
customer_recognized = Signal(providing_args=['customer', 'request']) | ||
|
||
if redis and hasattr(settings, 'SESSION_REDIS'): | ||
redis_con = dict((key, settings.SESSION_REDIS[key]) for key in ['host', 'port', 'db', 'socket_timeout']) | ||
pool = redis.ConnectionPool(**redis_con) | ||
redis_con = redis.Redis(connection_pool=pool) | ||
else: | ||
redis_con = type('Redis', (), {'publish': lambda *args: None})() | ||
|
||
|
||
def email_queued(): | ||
""" | ||
If SESSION_REDIS is configured, inform a separately running worker engine, that | ||
emails are ready for delivery. Call this function every time an email has been | ||
handled over to the Post-Office. | ||
""" | ||
redis_con.publish('django-SHOP', 'send_queued_mail') |
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