28 lines
818 B
Python
28 lines
818 B
Python
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())
|