I get the following error:
File "/Library/Python/2.7/site-packages/Django-1.8.2-py2.7.egg/django/utils/translation/trans_real.py", line 164, in _add_installed_apps_translations "The translation infrastructure cannot be initialized before the " django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
I have a project that is not really a django application, but a celery application. Therefore, I did not create wsgi.py or models.py or any of the typical files created by django-admin when starting a project or application.
I want to use djcelery to create periodic tasks using djcelery.schedules.DatabaseScheduler as described here Add, modify, delete celery.schedules at runtime and here How to dynamically add / remove periodic celery tasks (celerybeat)
The solution given here ( AppRegistryNotReady, translation error when deploying using uWSGI ) requires me to make changes to the vassal.ini file. In my implementation there is no vassal.ini file.
I will briefly describe my project -
proj apps.py tasks.py celeryconfig.py runproj.py
from celery import Celery os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'celeryconfig') myapp = Celery('myapp') myapp.config_from_object('celeryconfig') if __name__ == '__main__' myapp.worker_main('-B', '-S', 'djcelery.schedules.DatabaseScheduler')
from apps import myapp @myapp.task(name='msgprinter') def msg_printer(msg): print msg
from djcelery.models import PeriodicTask, IntervalSchedule intSch = IntervalSchedule(period='seconds', every=30) periodic_task = PeriodicTask( name = 'msg_printer_schedule', task = 'proj.tasks.msg_printer', interval = intSch, args=json.dump(['such wow']), ) periodic_task.save()
CELERY_ACCEPT_CONTENT = ['pickle', 'json'] BROKER_URL = 'amqp://guest@localhost' CELERY_IMPORTS = ('proj.tasks') CELERY_QUEUES = [Queue('default', Exchange('default', type='direct'), routing_key='default')]
Before starting the workers, I created the necessary tables using the django-admin migrate command. I see tables in the /home/test.db database.
First I run the workers - $python apps.py Then I save the schedule for the database to be re-executed by the celerybeat daemons - $python runproj.py