use celerybeat

This commit is contained in:
bakatrouble 2019-01-26 12:36:44 +03:00
parent 6a88f7da4b
commit ec01ab879f
8 changed files with 32 additions and 25 deletions

View File

@ -8,6 +8,16 @@ app = Celery('telegram_bots')
app.config_from_object({
'broker_url': 'redis://127.0.0.1:6379/1',
'result_backend': 'django-db',
'beat_scheduler': 'django_celery_beat.schedulers:DatabaseScheduler',
'worker_concurrency': 4,
'ONCE': {
'backend': 'celery_once.backends.Redis',
'settings': {
'url': 'redis://localhost:6379/0',
'default_timeout': 60 * 60,
}
}
})
app.autodiscover_tasks()

View File

@ -20,6 +20,8 @@ INSTALLED_APPS = [
'django_extensions',
'bootstrap4',
'djconfig',
'django_celery_results',
'django_celery_beat',
'config.suit_config.SuitConfig',
'django.contrib.admin',
@ -73,7 +75,7 @@ DATABASES = {
DATABASES['default']['ATOMIC_REQUESTS'] = True
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True

View File

@ -1,17 +0,0 @@
from time import sleep
from django.core.management import BaseCommand
from feeds.models import Feed
class Command(BaseCommand):
def handle(self, *args, **options):
try:
while True:
feeds = Feed.objects.filter(lock=False)
for feed in feeds:
feed.run_check()
sleep(5)
except KeyboardInterrupt:
pass

View File

@ -1,11 +1,17 @@
from pprint import pprint
from django.conf import settings
from celery_once import QueueOnce
from django.utils import timezone
from telebot import TeleBot
from djconfig import config
from config.celery import app
from feeds.models import Feed
@app.task(base=QueueOnce)
def check_feeds():
feeds = Feed.objects.filter(lock=False)
for feed in feeds:
feed.run_check()
@app.task()

View File

@ -2,15 +2,19 @@ amqp==2.3.2
beautifulsoup4==4.7.1
billiard==3.5.0.5
celery==4.2.1
celery-once==2.0.0
certifi==2018.11.29
chardet==3.0.4
Django==2.1.5
django-bootstrap4==0.0.7
django-celery-beat==1.4.0
django-celery-results==1.0.4
django-djconfig==0.9.0
django-environ==0.4.5
django-extensions==2.1.4
django-redis==4.10.0
-e git+https://github.com/darklow/django-suit@9941211bc7d63d94478a3c6479c51926dc75db09#egg=django_suit
django-timezone-field==3.0
django-yamlfield==1.0.3
enum34==1.1.6
idna==2.8
@ -18,6 +22,8 @@ kombu==4.2.2.post1
psycopg2-binary==2.7.6.1
PySocks==1.6.8
pyTelegramBotAPI==3.6.6
python-crontab==2.3.6
python-dateutil==2.7.5
pytz==2018.9
PyYAML==3.13
redis==3.0.1

View File

@ -22,12 +22,12 @@ autorestart=true
startsecs=10
stopwaitsecs=600
[program:bots_worker]
[program:bots_celerybeat]
user = http
directory = /srv/apps/bots
command=/srv/apps/bots/venv/bin/python /srv/apps/bots/manage.py worker_loop
stdout_logfile=/srv/apps/bots/logs/worker.log
stderr_logfile=/srv/apps/bots/logs/worker.log
command=/srv/apps/bots/venv/bin/celery beat --app=config -l info
stdout_logfile=/srv/apps/bots/logs/celerybeat.log
stderr_logfile=/srv/apps/bots/logs/celerybeat.log
autostart=true
autorestart=true
startsecs=10