Update deploy to set all settings at once (#2325)

This commit is contained in:
George Pollard
2022-08-31 11:34:35 +12:00
committed by GitHub
parent 8d23df328d
commit 8b31dfe4ef

View File

@ -1115,71 +1115,82 @@ class Client:
map(expand_agent, self.enable_dotnet) map(expand_agent, self.enable_dotnet)
) )
func = shutil.which("az") python_settings = []
assert func is not None dotnet_settings = []
for function_name in enable_dotnet: for function_name in enable_dotnet:
format_name = function_name.split("_") format_name = function_name.split("_")
dotnet_name = "".join(x.title() for x in format_name) dotnet_name = "".join(x.title() for x in format_name)
error: Optional[subprocess.CalledProcessError] = None # keep the python versions of http function to allow the service to be backward compatible
max_tries = 5 # with older version of the CLI and the agents
for i in range(max_tries): if function_name.startswith("queue_") or function_name.startswith(
try: "timer_"
# keep the python versions of http function to allow the service to be backward compatible ):
# with older version of the CLI and the agents logger.info(f"disabling PYTHON function: {function_name}")
if function_name.startswith( disable_python = "1"
"queue_" else:
) or function_name.startswith("timer_"): logger.info(f"enabling PYTHON function: {function_name}")
logger.info(f"disabling PYTHON function: {function_name}") disable_python = "0"
disable_python = "1"
else:
logger.info(f"enabling PYTHON function: {function_name}")
disable_python = "0"
subprocess.check_output(
[
func,
"functionapp",
"config",
"appsettings",
"set",
"--name",
self.application_name,
"--resource-group",
self.application_name,
"--settings",
f"AzureWebJobs.{function_name}.Disabled={disable_python}",
],
env=dict(os.environ, CLI_DEBUG="1"),
)
# enable dotnet function python_settings.append(
logger.info(f"enabling DOTNET function: {dotnet_name}") f"AzureWebJobs.{function_name}.Disabled={disable_python}"
subprocess.check_output( )
[
func, # enable dotnet function
"functionapp", logger.info(f"enabling DOTNET function: {dotnet_name}")
"config", dotnet_settings.append(f"AzureWebJobs.{dotnet_name}.Disabled=0")
"appsettings",
"set", func = shutil.which("az")
"--name", assert func is not None
self.application_name + DOTNET_APPLICATION_SUFFIX,
"--resource-group", max_tries = 5
self.application_name, error: Optional[subprocess.CalledProcessError] = None
"--settings", for i in range(max_tries):
f"AzureWebJobs.{dotnet_name}.Disabled=0", try:
], logger.info("updating Python settings")
env=dict(os.environ, CLI_DEBUG="1"), subprocess.check_output(
[
func,
"functionapp",
"config",
"appsettings",
"set",
"--name",
self.application_name,
"--resource-group",
self.application_name,
"--settings",
]
+ python_settings,
env=dict(os.environ, CLI_DEBUG="1"),
)
logger.info("updating .NET settings")
subprocess.check_output(
[
func,
"functionapp",
"config",
"appsettings",
"set",
"--name",
self.application_name + DOTNET_APPLICATION_SUFFIX,
"--resource-group",
self.application_name,
"--settings",
]
+ dotnet_settings,
env=dict(os.environ, CLI_DEBUG="1"),
)
break
except subprocess.CalledProcessError as err:
error = err
if i + 1 < max_tries:
logger.debug("func failure error: %s", err)
logger.warning(
"unable to update settings, waiting 60 seconds and trying again"
) )
break time.sleep(60)
except subprocess.CalledProcessError as err:
error = err
if i + 1 < max_tries:
logger.debug("func failure error: %s", err)
logger.warning(
f"{function_name} function didn't respond to "
"status change request, waiting 60 seconds "
"and trying again"
)
time.sleep(60)
if error is not None: if error is not None:
raise error raise error