implement queue for channel helper
This commit is contained in:
@@ -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}'
|
||||
|
||||
|
Reference in New Issue
Block a user