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({ app.config_from_object({
'broker_url': 'redis://127.0.0.1:6379/1', '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() app.autodiscover_tasks()

View File

@ -20,6 +20,8 @@ INSTALLED_APPS = [
'django_extensions', 'django_extensions',
'bootstrap4', 'bootstrap4',
'djconfig', 'djconfig',
'django_celery_results',
'django_celery_beat',
'config.suit_config.SuitConfig', 'config.suit_config.SuitConfig',
'django.contrib.admin', 'django.contrib.admin',
@ -73,7 +75,7 @@ DATABASES = {
DATABASES['default']['ATOMIC_REQUESTS'] = True DATABASES['default']['ATOMIC_REQUESTS'] = True
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC' TIME_ZONE = 'Europe/Moscow'
USE_I18N = True USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = 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 celery_once import QueueOnce
from django.conf import settings
from django.utils import timezone from django.utils import timezone
from telebot import TeleBot from telebot import TeleBot
from djconfig import config from djconfig import config
from config.celery import app 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() @app.task()

View File

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

View File

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