|
@@ -8,6 +8,7 @@ from django_pglocks import advisory_lock
|
|
|
from rq.timeouts import JobTimeoutException
|
|
from rq.timeouts import JobTimeoutException
|
|
|
|
|
|
|
|
from core.choices import JobStatusChoices
|
|
from core.choices import JobStatusChoices
|
|
|
|
|
+from core.exceptions import JobFailed
|
|
|
from core.models import Job, ObjectType
|
|
from core.models import Job, ObjectType
|
|
|
from netbox.constants import ADVISORY_LOCK_KEYS
|
|
from netbox.constants import ADVISORY_LOCK_KEYS
|
|
|
from netbox.registry import registry
|
|
from netbox.registry import registry
|
|
@@ -73,15 +74,21 @@ class JobRunner(ABC):
|
|
|
This method is called by the Job Scheduler to handle the execution of all job commands. It will maintain the
|
|
This method is called by the Job Scheduler to handle the execution of all job commands. It will maintain the
|
|
|
job's metadata and handle errors. For periodic jobs, a new job is automatically scheduled using its `interval`.
|
|
job's metadata and handle errors. For periodic jobs, a new job is automatically scheduled using its `interval`.
|
|
|
"""
|
|
"""
|
|
|
|
|
+ logger = logging.getLogger('netbox.jobs')
|
|
|
|
|
+
|
|
|
try:
|
|
try:
|
|
|
job.start()
|
|
job.start()
|
|
|
cls(job).run(*args, **kwargs)
|
|
cls(job).run(*args, **kwargs)
|
|
|
job.terminate()
|
|
job.terminate()
|
|
|
|
|
|
|
|
|
|
+ except JobFailed:
|
|
|
|
|
+ logger.warning(f"Job {job} failed")
|
|
|
|
|
+ job.terminate(status=JobStatusChoices.STATUS_FAILED)
|
|
|
|
|
+
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))
|
|
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))
|
|
|
if type(e) is JobTimeoutException:
|
|
if type(e) is JobTimeoutException:
|
|
|
- logging.error(e)
|
|
|
|
|
|
|
+ logger.error(e)
|
|
|
|
|
|
|
|
# If the executed job is a periodic job, schedule its next execution at the specified interval.
|
|
# If the executed job is a periodic job, schedule its next execution at the specified interval.
|
|
|
finally:
|
|
finally:
|