Tivix / django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-)
www.tivix.com
MIT License
900 stars 193 forks source link

Django 1.9 compatibility #70

Closed ernestoalejo closed 8 years ago

ernestoalejo commented 8 years ago

In Django 1.9 you can no longer load any models on app startup.

Traceback (most recent call last):
  File "manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 324, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/django_cron/__init__.py", line 6, in <module>
    from django_cron.models import CronJobLog
  File "/usr/local/lib/python2.7/dist-packages/django_cron/models.py", line 4, in <module>
    class CronJobLog(models.Model):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 94, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 239, in get_containing_app_config
    self.check_apps_ready()
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Maberi commented 8 years ago

I've patched it by moving "from django_cron.models import CronJobLog" from global imports to local imports in the methods using CronJobLog (should_run_now and enter ) in django_cron__init__.py

eriktelepovsky commented 8 years ago

+1

eriktelepovsky commented 8 years ago

I created PR #71 for this

chachra commented 8 years ago

Thanks @eriktelepovsky - appreciate it. Will review it / merge today.

-Sumit

chachra commented 8 years ago

Merged into master, but want to refactor a bit.

chachra commented 8 years ago

https://pypi.python.org/pypi/django-cron/0.4.6 pushed with the fix.