mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 23:02:19 +00:00
Convert validation processing to a celery task
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
ROOT=/home/matalok/auth/auth
|
ROOT=/home/matalok/auth/auth
|
||||||
|
|
||||||
@daily $ROOT/run-cron.py reddit.cron UpdateAPIs > $ROOT/logs/redditapi-update.log 2>&1
|
@daily $ROOT/run-cron.py reddit.cron UpdateAPIs > $ROOT/logs/redditapi-update.log 2>&1
|
||||||
*/10 * * * * $ROOT/run-cron.py reddit.cron ProcessValidations > $ROOT/logs/reddit-validations.log 2>&1
|
|
||||||
*/5 * * * * $ROOT/run-cron.py eve_api.cron UpdateAPIs > $ROOT/logs/eveapi-update.log 2>&1
|
*/5 * * * * $ROOT/run-cron.py eve_api.cron UpdateAPIs > $ROOT/logs/eveapi-update.log 2>&1
|
||||||
0 */6 * * * $ROOT/run-cron.py eve_api.cron AllianceUpdate > $ROOT/logs/alliance-update.log 2>&1
|
0 */6 * * * $ROOT/run-cron.py eve_api.cron AllianceUpdate > $ROOT/logs/alliance-update.log 2>&1
|
||||||
@daily $ROOT/run-cron.py eve_proxy.cron ClearStaleCache > $ROOT/logs/cache-clear.log 2>&1
|
@daily $ROOT/run-cron.py eve_proxy.cron ClearStaleCache > $ROOT/logs/cache-clear.log 2>&1
|
||||||
|
|||||||
@@ -33,47 +33,3 @@ class UpdateAPIs():
|
|||||||
else:
|
else:
|
||||||
acc.save()
|
acc.save()
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
|
|
||||||
|
|
||||||
class APIKeyParser:
|
|
||||||
dictitems = {}
|
|
||||||
|
|
||||||
def __init__(self, key):
|
|
||||||
rows = key.split('\n')
|
|
||||||
for row in rows:
|
|
||||||
key = row.split(":")[0].replace(" ", "_").lower().strip()
|
|
||||||
value = row.split(":")[1].strip()
|
|
||||||
|
|
||||||
self.dictitems[key] = value
|
|
||||||
|
|
||||||
def __getattr__(self, key):
|
|
||||||
return self.dictitems[key]
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "%s:%s" % (self.user_id, self.api_key)
|
|
||||||
|
|
||||||
class ProcessValidations():
|
|
||||||
"""
|
|
||||||
Grabs all Reddit Mail and processes validations
|
|
||||||
"""
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _logger(self):
|
|
||||||
if not hasattr(self, '__logger'):
|
|
||||||
self.__logger = logging.getLogger(__name__)
|
|
||||||
return self.__logger
|
|
||||||
|
|
||||||
def job(self, args):
|
|
||||||
inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWORD)
|
|
||||||
|
|
||||||
for msg in inbox:
|
|
||||||
if not msg.was_comment:
|
|
||||||
try:
|
|
||||||
acc = RedditAccount.objects.get(username__iexact=msg.author)
|
|
||||||
if not acc.validated and msg.subject == "Validation: %s" % acc.user.username:
|
|
||||||
self._logger.info("Validated %s" % acc.user.username)
|
|
||||||
acc.validated = True
|
|
||||||
acc.save()
|
|
||||||
except RedditAccount.DoesNotExist:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from celery.decorators import task
|
from celery.decorators import task
|
||||||
|
from reddit.models import RedditAccount
|
||||||
from reddit.api import Inbox
|
from reddit.api import Inbox
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
@@ -7,3 +8,18 @@ def send_reddit_message(to, subject, message):
|
|||||||
ib = Inbox(username=settings.REDDIT_USER, password=settings.REDDIT_PASSWORD)
|
ib = Inbox(username=settings.REDDIT_USER, password=settings.REDDIT_PASSWORD)
|
||||||
ib.send(to, subject, message)
|
ib.send(to, subject, message)
|
||||||
|
|
||||||
|
@task(ignore_result=True)
|
||||||
|
def process_validations():
|
||||||
|
log = process_validations.get_logger()
|
||||||
|
inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWORD)
|
||||||
|
for msg in inbox:
|
||||||
|
if not msg.was_comment:
|
||||||
|
try:
|
||||||
|
acc = RedditAccount.objects.get(username__iexact=msg.author)
|
||||||
|
if not acc.validated and msg.subject == "Validation: %s" % acc.user.username:
|
||||||
|
log.info("Validated %s" % acc.user.username)
|
||||||
|
acc.validated = True
|
||||||
|
acc.save()
|
||||||
|
except RedditAccount.DoesNotExist:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|||||||
11
settings.py
11
settings.py
@@ -156,6 +156,13 @@ try:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
djcelery.setup_loader()
|
djcelery.setup_loader()
|
||||||
|
|
||||||
|
### Celery Schedule
|
||||||
|
|
||||||
|
CELERYBEAT_SCHEDULE = {
|
||||||
|
"reddit-validations": {
|
||||||
|
"task": "reddit.tasks.process_validations",
|
||||||
|
"schedule": timedelta(minutes=10),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user