Skip to content

Commit

Permalink
add exceptions prints
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Sikora committed Aug 9, 2013
1 parent be41b05 commit 6c87f0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions django_cron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __should_run_now(self, cron_job, force=False):
return False

@classmethod
def run(self, cron_job, force=False):
def run(self, cron_job, force=False, silent=False):
"""
apply the logic of the schedule and call do() on the CronJobBase class
"""
Expand All @@ -96,8 +96,11 @@ def run(self, cron_job, force=False):
cron_log.is_success = True
cron_log.message = msg or ''
except Exception:
error = traceback.format_exc()
if not silent:
print error
cron_log.is_success = False
cron_log.message = traceback.format_exc()[-1000:]
cron_log.message = error[-1000:]
cron_log.ran_at_time = self.user_time if self.user_time else None
cron_log.end_time = timezone.now()
cron_log.save()
6 changes: 4 additions & 2 deletions django_cron/management/commands/runcrons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from datetime import datetime
from optparse import make_option
import traceback

from django.core.management.base import BaseCommand
from django.conf import settings
Expand Down Expand Up @@ -49,7 +50,8 @@ def handle(self, *args, **options):
try:
crons_to_run = map(lambda x: get_class(x), cron_class_names)
except:
print 'Make sure these are valid cron class names: %s' % cron_class_names
error = traceback.format_exc()
print 'Make sure these are valid cron class names: %s\n%s' % (cron_class_names, error)
sys.exit()

for cron_class in crons_to_run:
Expand All @@ -71,7 +73,7 @@ def run_cron_with_cache_check(cron_class, force=False, silent=False):
pass
cache.set(cron_class.__name__, timezone.now(), timeout)
instance = cron_class()
CronJobManager.run(instance, force)
CronJobManager.run(instance, force, silent)
cache.delete(cron_class.__name__)
else:
if not silent:
Expand Down

0 comments on commit 6c87f0d

Please sign in to comment.