misc: log traceback for cron job exceptions (#44236)

This commit is contained in:
Benjamin Dauvergne 2020-06-18 17:59:46 +02:00
parent d19b7c01ed
commit 31cd22bab5
2 changed files with 3 additions and 2 deletions

View File

@ -48,7 +48,8 @@ class Command(BaseCommand):
try:
getattr(connector, frequency)()
except Exception as e:
connector.logger.error('error running %s job (%r)' % (frequency, e))
connector.logger.exception('connector "%s.%s" error running %s job' % (
connector.get_connector_slug(), connector.slug, frequency))
errors.append({'connector': connector, 'exception': e, 'traceback': traceback.format_exc()})
if errors:
for error in errors:

View File

@ -20,4 +20,4 @@ def test_cron_error(db, caplog):
new=mock.Mock(side_effect=excep)):
with pytest.raises(CommandError):
call_command('cron', 'hourly')
assert caplog.records[0].message == "error running hourly job (%s)" % repr(excep)
assert caplog.records[0].message == 'connector "base-adresse.base-adresse" error running hourly job'