automate: move working_dir to be set in constructor

This commit is contained in:
Iain Learmonth 2022-11-28 18:55:10 +00:00
parent efdaad977a
commit 109851745b
7 changed files with 59 additions and 43 deletions

View file

@ -38,7 +38,7 @@ from app.terraform.proxy.cloudfront import ProxyCloudfrontAutomation
from app.terraform.proxy.fastly import ProxyFastlyAutomation
jobs = {
x.short_name: x
x.short_name: x # type: ignore[attr-defined]
for x in [
AlarmEotkAwsAutomation,
AlarmProxyAzureCdnAutomation,
@ -78,7 +78,7 @@ def run_all(**kwargs: bool) -> None:
:return: None
"""
for job in jobs.values():
run_job(job, **kwargs) # type: ignore
run_job(job, **kwargs)
def run_job(job_cls: Type[BaseAutomation], *,
@ -107,10 +107,10 @@ def run_job(job_cls: Type[BaseAutomation], *,
return
automation.state = AutomationState.RUNNING
db.session.commit()
job: BaseAutomation = job_cls()
try:
job: BaseAutomation = job_cls()
tempdir_path = tempfile.mkdtemp()
success, logs = job.automate(tempdir_path)
success, logs = job.automate()
# 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
@ -162,7 +162,7 @@ class AutomateCliHandler(BaseCliHandler):
def run(self) -> None:
with app.app_context():
if self.args.job:
run_job(jobs[self.args.job], # type: ignore
run_job(jobs[self.args.job],
force=self.args.force,
ignore_schedule=self.args.ignore_schedule)
elif self.args.all: