signal backend, app cleanup
This commit is contained in:
parent
4b157ed1d1
commit
6f18890739
43 changed files with 695 additions and 124 deletions
28
app/item/tasks.py
Normal file
28
app/item/tasks.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from celery.schedules import crontab
|
||||
from django.conf import settings
|
||||
|
||||
from ..signalbot import rpc
|
||||
from ..celery import app
|
||||
|
||||
from . import models
|
||||
|
||||
@app.task(queue="default")
|
||||
def announce_items():
|
||||
pass
|
||||
|
||||
|
||||
@app.task(queue="default")
|
||||
def notify_moderators(id, link):
|
||||
comment = models.Comment.objects.filter(id=id).first()
|
||||
if comment:
|
||||
message = "%s commnented on %s\n\n%s" % (comment.name, link, comment.text)
|
||||
r = rpc.send(message, group=settings.SIGNAL_MODERATORS_GROUP)
|
||||
if r and "timestamp" in r:
|
||||
comment.data["moderator_ts"] = r["timestamp"]
|
||||
comment.save()
|
||||
else:
|
||||
print("failed to notify", r)
|
||||
|
||||
@app.on_after_finalize.connect
|
||||
def setup_periodic_tasks(sender, **kwargs):
|
||||
sender.add_periodic_task(crontab(minute="*/2"), announce_items.s())
|
||||
Loading…
Add table
Add a link
Reference in a new issue