cron: log and capture exceptions, do not create logged errors (#88783)
gitea/wcs/pipeline/head There was a failure building this commit
Details
gitea/wcs/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
dc473b7378
commit
1e5585883c
|
@ -526,6 +526,31 @@ def test_cron_command_rewind_jobs(settings, freezer):
|
|||
assert sorted(jobs) == ['job1', 'job2', 'job3']
|
||||
|
||||
|
||||
def test_cron_command_job_exception(settings):
|
||||
create_temporary_pub()
|
||||
|
||||
def job1(pub, job=None):
|
||||
raise Exception('Error')
|
||||
|
||||
@classmethod
|
||||
def register_test_cronjobs(cls):
|
||||
cls.register_cronjob(CronJob(job1, name='job1', days=[10]))
|
||||
|
||||
get_publisher().set_tenant_by_hostname('example.net')
|
||||
sql.mark_cron_status('done')
|
||||
|
||||
with mock.patch('wcs.publisher.WcsPublisher.register_cronjobs', register_test_cronjobs):
|
||||
get_publisher_class().cronjobs = []
|
||||
call_command('cron', job_name='job1', domain='example.net')
|
||||
assert get_logs('example.net') == [
|
||||
'start',
|
||||
"running jobs: ['job1']",
|
||||
'exception running job job1: Error',
|
||||
]
|
||||
|
||||
clean_temporary_pub()
|
||||
|
||||
|
||||
def test_clean_afterjobs():
|
||||
pub = create_temporary_pub()
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
@ -128,4 +129,5 @@ def cron_worker(publisher, since, job_name=None):
|
|||
with job.log_long_job():
|
||||
job.function(publisher, job=job)
|
||||
except Exception as e:
|
||||
publisher.record_error(exception=e, context='[CRON]', notify=True)
|
||||
job.log(f'exception running job {job.name}: {e}')
|
||||
publisher.capture_exception(sys.exc_info())
|
||||
|
|
Loading…
Reference in New Issue