Use disposable temporary directories to run automation jobs
This commit is contained in:
parent
9e5280280f
commit
0ebfe28b89
5 changed files with 36 additions and 42 deletions
|
@ -1,5 +1,7 @@
|
|||
import datetime
|
||||
import logging
|
||||
import shutil
|
||||
import tempfile
|
||||
from traceback import TracebackException
|
||||
from typing import Type
|
||||
|
||||
|
@ -107,7 +109,8 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
db.session.commit()
|
||||
job: BaseAutomation = job_cls()
|
||||
try:
|
||||
success, logs = job.automate()
|
||||
tempdir_path = tempfile.mkdtemp()
|
||||
success, logs = job.automate(tempdir_path)
|
||||
# We want to catch any and all exceptions that would cause problems here, because
|
||||
# the error handling process isn't really handling the error, but rather causing it
|
||||
# to be logged for investigation. Catching more specific exceptions would just mean that
|
||||
|
@ -120,6 +123,7 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
automation.state = AutomationState.IDLE
|
||||
automation.next_run = datetime.datetime.utcnow() + datetime.timedelta(
|
||||
minutes=getattr(job, "frequency", 7))
|
||||
shutil.rmtree(tempdir_path)
|
||||
else:
|
||||
automation.state = AutomationState.ERROR
|
||||
automation.enabled = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue