Nagashree-KR / django-cron

Automatically exported from code.google.com/p/django-cron
MIT License
0 stars 0 forks source link

simple enhancement: run cronjobs from management.py #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Even on systems where cron/shell access is available, it is preferable to
only have one actual cronjob and let django-cron do the rest, because that
does not only make deployment easier, but also leads to cleaner application
code.

Fortunately, it is very simple to enhance django-cron this way - the
attached patch enhances manage.py with cron-running capabilities.

Original issue reported on code.google.com by chris.vigelius on 16 Jun 2008 at 10:11

Attachments:

GoogleCodeExporter commented 8 years ago
I think with all my changes, your patch may not work anymore. The problem with 
this
approach though (if I understand correctly) is you need an actual cron job to 
kick it
off.

The goal of this project (as stated on the project home page) is to enable 
cron-like
functions without shell access, (or whatever other reason) for people on shared
hosting etc.

Original comment by Jim.mixt...@gmail.com on 18 Apr 2009 at 1:17

GoogleCodeExporter commented 8 years ago
Is this also intended to allow you to test whether the cron job code works from 
a
command line?  In that case I can see the usefulness when setting up jobs that 
need
to be tested.

Original comment by jchampio...@gtempaccount.com on 15 Jun 2009 at 7:27

GoogleCodeExporter commented 8 years ago
I agree with the statement in the original issue: "it is preferable to only 
have one
actual cronjob and let django-cron do the rest". Even when cron is available on 
the
system, it would be useful to have a simple way to register jobs with a central 
cron
manager.

Original comment by theMich...@gmail.com on 20 Jul 2009 at 6:05

GoogleCodeExporter commented 8 years ago
Attached is an updated patch. Some changes were needed in __init__.py and 
base.py, as
invoking Timer() makes the script run forever from the command line.

I don't think this code is quite acceptable yet (it doesn't return any useful
information upon running, for example) but it seems a useful start.

(As I noted above, I think this is useful functionality. A cron-enabled hosting
environment would simply use a cron script to run "manage.py cronjobs", and the
urls.py configuration is not needed.)

Original comment by theMich...@gmail.com on 20 Jul 2009 at 7:21

Attachments:

GoogleCodeExporter commented 8 years ago
An update: my changes are not compatible with lines 39-47 of base.py, as it'll 
lead
to all jobs being deleted on every cron run. I realize that block makes sense 
for the
thread/timer approach, but it doesn't help in this case. I just deleted those 
lines
from my code, but I'll consider a cleaner solution.

Original comment by theMich...@gmail.com on 21 Jul 2009 at 2:14

GoogleCodeExporter commented 8 years ago
I think this patch is an excellent idea. I'm on the verge of writing my own
cron-manager to do exactly that.

Original comment by andybak on 23 Oct 2009 at 2:01

GoogleCodeExporter commented 8 years ago
I applied the patch manually to r26 and it works perfectly. (by manually I mean 
by
reading the patch and making the individual changes).

Original comment by andybak on 26 Oct 2009 at 4:45

GoogleCodeExporter commented 8 years ago
A further comment is that I couldn't get django-cron working until I used the 
patch.
I didn't try too hard as I preferred to use the manage.py method (shared 
hosting so
memory is at a premium and I thought the original method of execution might 
leave an
instance of Django hanging around)

Original comment by andybak on 26 Oct 2009 at 4:48