Skip to content

Commit

Permalink
Merge pull request #9 from fruitschen/master
Browse files Browse the repository at this point in the history
auto delete a job if there's trouble unpickle a job
  • Loading branch information
andybak committed May 8, 2014
2 parents 7360a9f + 87e5b10 commit f34e864
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions django_cron/base.py
Expand Up @@ -175,11 +175,15 @@ def execute(self, start_timer=True, registering=False):
last_run = datetime(job.last_run.year, job.last_run.month, job.last_run.day, job.last_run.hour, job.last_run.minute)

if (now - last_run) >= timedelta(minutes=job.run_frequency):
inst = cPickle.loads(str(job.instance))
args = cPickle.loads(str(job.args))
kwargs = cPickle.loads(str(job.kwargs))

try:
try:
inst = cPickle.loads(str(job.instance))
args = cPickle.loads(str(job.args))
kwargs = cPickle.loads(str(job.kwargs))
except:
job.delete()
raise

inst.run(*args, **kwargs)
job.last_run = datetime.now()
job.save()
Expand All @@ -194,8 +198,9 @@ def execute(self, start_timer=True, registering=False):
except:
#Code will fail in django 1.4 or later as user.message_set is no longer available
pass
job.queued = False
job.save()
if job.id:#job might have been deleted.
job.queued = False
job.save()
import traceback
exc_info = sys.exc_info()
stack = ''.join(traceback.format_tb(exc_info[2]))
Expand Down Expand Up @@ -228,3 +233,4 @@ def mail_exception(self, job, module, err, stack=None):

cronScheduler = CronScheduler()


0 comments on commit f34e864

Please sign in to comment.