Question

I am trying to use Django-cron to regularly run a script on my Django server. It seems as though the cronScheduler is registering the Test class as "class ran" prints to my terminal, but I have not found any indication that the job is run (i.e. I have not seen "job ran" printed to the terminal). In case I shouldn't have been relying on printing to know if the job was running, I also watched the django_cron_job table in my database for a few minutes to see if the job's "last_run" value changed after initially sending a request to my server but I found that it did not.

Just so you know: Each time I test I have been hitting my server with one request so that the job will start, I have modified the CRON_POLLING_FREQUENCY in my settings file to be lower than the run_every value I specify for the job, and also ensured that the job was set to queued per this posts' suggestion: Similar problem.

In order to solve an error I was originally getting ("AttributeError: 'Settings' object has no attribute 'PROJECT_DIR'"), I set my PROJECT_DIR to os.path.dirname(__file__) in settings.py. Could that be a problem?

I also get the following when I start the server but I've looked into it and couldn't find any reason why it would be the problem:

"RuntimeWarning: DateTimeField received a naive datetime (2013-07-23 13:55:56.016085) while time zone support is active."

The only other thing of note is that I often retrieve the following printout to my terminal a few seconds after relaunching the server and hitting the server with a request, but it only happens once until I restart the server:

"Already executing Oops! process with pid 17099 is not running. Fixing status in db. Validating models..."

My cron.py file:

from django_cron import cronScheduler, Job, HOUR, DAY, WEEK, MONTH
import sys

class Test(Job):
    print "class ran"
    run_every=2
    def job(self):
        print "job ran"

cronScheduler.register(Test)
Was it helpful?

Solution

Got it: I looked over things again a few times after posting and noticed that the last_run date in the database was hours before my current time, so my job didn't think it needed to start until it finally hit that time + my run_every specification. So the DateTimeField RuntimeWarning was the problem after all. I tested it by manually changing the last_run date and I got the printout as expected. Now I just need to figure out how to solve this timezone related problem. Hope this can help someone!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top