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 datetime
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
from traceback import TracebackException
|
from traceback import TracebackException
|
||||||
|
@ -108,8 +109,12 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
||||||
automation.state = AutomationState.RUNNING
|
automation.state = AutomationState.RUNNING
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
try:
|
try:
|
||||||
job: BaseAutomation = job_cls()
|
if 'TERRAFORM_DIRECTORY' in app.config:
|
||||||
tempdir_path = tempfile.mkdtemp()
|
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()
|
success, logs = job.automate()
|
||||||
# We want to catch any and all exceptions that would cause problems here, because
|
# 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
|
# 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.state = AutomationState.IDLE
|
||||||
automation.next_run = datetime.datetime.utcnow() + datetime.timedelta(
|
automation.next_run = datetime.datetime.utcnow() + datetime.timedelta(
|
||||||
minutes=getattr(job, "frequency", 7))
|
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:
|
else:
|
||||||
automation.state = AutomationState.ERROR
|
automation.state = AutomationState.ERROR
|
||||||
automation.enabled = False
|
automation.enabled = False
|
||||||
|
|
|
@ -19,9 +19,7 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
||||||
"rfc2136_nameserver",
|
"rfc2136_nameserver",
|
||||||
"rfc2136_tsig_key",
|
"rfc2136_tsig_key",
|
||||||
"rfc2136_tsig_secret",
|
"rfc2136_tsig_secret",
|
||||||
"smart_zone",
|
"smart_zone"
|
||||||
"maxmind_account_id",
|
|
||||||
"maxmind_license_key"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
template = """
|
template = """
|
||||||
|
@ -30,10 +28,10 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
||||||
required_providers {
|
required_providers {
|
||||||
acme = {
|
acme = {
|
||||||
source = "vancluever/acme"
|
source = "vancluever/acme"
|
||||||
version = "~> 2.8.0"
|
version = "~> 2.11.0"
|
||||||
}
|
}
|
||||||
aws = {
|
aws = {
|
||||||
version = "~> 4.4.0"
|
version = "~> 4.41.0"
|
||||||
}
|
}
|
||||||
dns = {
|
dns = {
|
||||||
version = "~> 3.2.3"
|
version = "~> 3.2.3"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue