feat(automate): make temporary working dir optional
This commit is contained in:
parent
109851745b
commit
d9158ac942
2 changed files with 13 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from traceback import TracebackException
|
||||
|
@ -108,8 +109,12 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
automation.state = AutomationState.RUNNING
|
||||
db.session.commit()
|
||||
try:
|
||||
job: BaseAutomation = job_cls()
|
||||
tempdir_path = tempfile.mkdtemp()
|
||||
if 'TERRAFORM_DIRECTORY' in app.config:
|
||||
working_dir = os.path.join(app.config['TERRAFORM_DIRECTORY'],
|
||||
job_cls.short_name or job_cls.__class__.__name__.lower())
|
||||
else:
|
||||
working_dir = tempfile.mkdtemp()
|
||||
job: BaseAutomation = job_cls(working_dir)
|
||||
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
|
||||
|
@ -123,7 +128,9 @@ 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)
|
||||
if not 'TERRAFORM_DIRECTORY' in app.config:
|
||||
# We used a temporary working directory
|
||||
shutil.rmtree(working_dir)
|
||||
else:
|
||||
automation.state = AutomationState.ERROR
|
||||
automation.enabled = False
|
||||
|
|
|
@ -19,9 +19,7 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
|||
"rfc2136_nameserver",
|
||||
"rfc2136_tsig_key",
|
||||
"rfc2136_tsig_secret",
|
||||
"smart_zone",
|
||||
"maxmind_account_id",
|
||||
"maxmind_license_key"
|
||||
"smart_zone"
|
||||
]
|
||||
|
||||
template = """
|
||||
|
@ -30,10 +28,10 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
|||
required_providers {
|
||||
acme = {
|
||||
source = "vancluever/acme"
|
||||
version = "~> 2.8.0"
|
||||
version = "~> 2.11.0"
|
||||
}
|
||||
aws = {
|
||||
version = "~> 4.4.0"
|
||||
version = "~> 4.41.0"
|
||||
}
|
||||
dns = {
|
||||
version = "~> 3.2.3"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue