From 4b2d491c2908ec6b677fe494547774bf7d323cb5 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Sun, 6 Jun 2021 16:21:28 +0300 Subject: Fix django.core.exceptions.AppRegistryNotReady in scheduler --- README.md | 2 +- servo/__init__.py | 5 ----- servo/celery.py | 24 ------------------------ servo/management/commands/scheduler.py | 5 ++++- servo/tasks.py | 8 +++----- 5 files changed, 8 insertions(+), 36 deletions(-) delete mode 100644 servo/celery.py diff --git a/README.md b/README.md index feb29f9..d33c6ac 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ For testing, you can run Servo without any extra setup: If you want to run rules, set ENABLE_RULES = True and start the worker task and scheduler: - $ ./manage.py rqworker & + $ rq worker --with-scheduler & $ ./manage.py scheduler Then fire up your browser and got to [http://localhost:8000/](http://localhost:8000/) diff --git a/servo/__init__.py b/servo/__init__.py index b64e43e..e69de29 100644 --- a/servo/__init__.py +++ b/servo/__init__.py @@ -1,5 +0,0 @@ -from __future__ import absolute_import - -# This will make sure the app is always imported when -# Django starts so that shared_task will use this app. -from .celery import app as celery_app diff --git a/servo/celery.py b/servo/celery.py deleted file mode 100644 index 75dc4d7..0000000 --- a/servo/celery.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- - -from __future__ import absolute_import - -import os - -from celery import Celery - -# set the default Django settings module for the 'celery' program. -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings') - -from django.conf import settings - -app = Celery('servo') - -# Using a string here means the worker will not have to -# pickle the object when using Windows. -app.config_from_object('django.conf:settings') -app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) - - -@app.task(bind=True) -def debug_task(self): - print('Request: {0!r}'.format(self.request)) diff --git a/servo/management/commands/scheduler.py b/servo/management/commands/scheduler.py index 18018e5..c400b7b 100644 --- a/servo/management/commands/scheduler.py +++ b/servo/management/commands/scheduler.py @@ -1,9 +1,12 @@ from datetime import datetime -import django_rq +import django + from django.core.management.base import BaseCommand from django_rq.management.commands import rqscheduler +import django_rq +django.setup() # To avoid django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. from servo.tasks import check_mail diff --git a/servo/tasks.py b/servo/tasks.py index 1d55136..c31dd22 100644 --- a/servo/tasks.py +++ b/servo/tasks.py @@ -1,9 +1,6 @@ # -*- coding: utf-8 -*- -import email -import logging from email.parser import BytesParser -from django.conf import settings from django.core.cache import cache from servo.lib.utils import empty @@ -12,10 +9,11 @@ from servo.models import Configuration, User, Order, Note, Template def get_rules(): - """Get the rules from the JSON file and cache them. + """ + Get the rules from the JSON file and cache them. Fail silently if not configured. - @FIXME: Need GUI for managing local_rules.json! + @TODO: Need GUI for managing local_rules.json! """ import json -- cgit v1.2.3