implement queue for channel helper

This commit is contained in:
2019-11-24 19:22:30 +03:00
parent 7725691c1e
commit 9d07c774a3
6 changed files with 113 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils import timezone
from telegram import Bot
from telegram.ext import Dispatcher
@@ -31,6 +32,13 @@ class TelegramBot(models.Model):
self.config.build_dispatcher(dispatcher)
return dispatcher
def run_periodic_task(self):
if not hasattr(self.config, 'periodic_task') or not self.periodic_interval or \
(self.periodic_last_run and self.periodic_last_run > timezone.now() - self.periodic_interval):
return
self.config.periodic_task(self.get_bot())
self.periodic_last_run = timezone.now()
def __str__(self):
return f'#{self.pk} {self.title}'