cmds.secrets.lib.DistroContext: Hold ctx + store open
Each run() call opens and closes the exec context, so a compile that issues one remote command at a time opened and closed the SSH connection for every command: a single deploy on dynamix opened around a hundred sessions and took several minutes. run() opens and closes through the FileContext reference counter, so holding the context (and the secret store) open for the whole compile turns the per-command open() / close() pairs into counter bumps, and the connection is established only once. This commit wraps the target listing and the per-target loop in an "async with" on both, which drops the counter to zero at end of scope and closes the contexts. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
65e55a1119
commit
7cec4007da
1 changed files with 19 additions and 14 deletions
|
|
@ -90,20 +90,25 @@ class DistroContext(FilesContext):
|
|||
ret: list[str] = []
|
||||
failed: list[str] = []
|
||||
missing = 0
|
||||
targets = await self.list_compilation_targets(pkg_names)
|
||||
for target in targets:
|
||||
try:
|
||||
ok = await self.compile_template_file(target, default_attrs)
|
||||
except Exception as e:
|
||||
if not keep_going:
|
||||
raise
|
||||
log(ERR, f'{target}: {e}')
|
||||
failed.append(target)
|
||||
continue
|
||||
if ok:
|
||||
ret.append(target)
|
||||
else:
|
||||
missing += 1
|
||||
# -- Keep the exec context and the store open across the whole
|
||||
# compile, so the run() calls in the per-target operations
|
||||
# bump the reference counter instead of opening and closing
|
||||
# the connection for every remote command.
|
||||
async with self.ctx, self.store:
|
||||
targets = await self.list_compilation_targets(pkg_names)
|
||||
for target in targets:
|
||||
try:
|
||||
ok = await self.compile_template_file(target, default_attrs)
|
||||
except Exception as e:
|
||||
if not keep_going:
|
||||
raise
|
||||
log(ERR, f'{target}: {e}')
|
||||
failed.append(target)
|
||||
continue
|
||||
if ok:
|
||||
ret.append(target)
|
||||
else:
|
||||
missing += 1
|
||||
if missing > 0:
|
||||
from ....lib.util import pretty_cmd
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue