3

I'm trying to setup django-cron https://github.com/Tivix/django-cron I've finished migrating it but running python2.7 manage.py runcrons throws this error

Make sure these are valid cron class names: ['rest.cron.MyCronJob']
Traceback (most recent call last):
  File "/home/kbuzz/lib/python2.7/django_cron/management/commands/runcrons.py", line 35, in handle
    crons_to_run = [get_class(x) for x in cron_class_names]
  File "/home/kbuzz/lib/python2.7/django_cron/__init__.py", line 23, in get_class
    m = __import__(module)
ImportError: No module named cron

I created a file cron.py in the app rest and also added the same code to views

from django_cron import CronJobBase, Schedule
import datetime

class MyCronJob(CronJobBase):
    RUN_EVERY_MINS = 10 # every 10 minutes
    schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
    code = 'rest.movies_cron' # a unique code

    def do(self):
        check = file('test.txt','a')
        today = datetime.datetime.now()
        check.write(today.isoformat())
        check.close()

In the settings file I added this, I expect it's a linking issue (code not found).

CRON_CLASSES = [
    "rest.cron.MyCronJob",
]
Samuel Muiruri
  • 625
  • 1
  • 5
  • 13
  • If you append your project name, `"yourproject.rest.cron.MyCronJob"`, does anything change? – Alex Morozov Jan 12 '16 at 08:47
  • @AlexMorozov no it doesn't fix it, still getting the same error, I'm thinking because cron.py is a file not a folder calling .cron.MyCronJob isn't the right way – Samuel Muiruri Jan 12 '16 at 10:45

1 Answers1

1

I had the same issue. cron.py should be inside of the rest app folder not the rest project folder. I have a hunch that you had the cron.py inside the rest project folder.

Gobi Dasu
  • 459
  • 1
  • 6
  • 22