feat: make sleep time a function paramater instead of hard-coding it
This commit is contained in:
parent
353230a493
commit
2942724700
14
main.py
14
main.py
@ -25,11 +25,11 @@ PROXMOX_USER_FULL: str | None = os.environ.get('PROXMOX_USER_FULL')
|
|||||||
PROXMOX_PASSWORD: str | None = os.environ.get('PROXMOX_PASSWORD')
|
PROXMOX_PASSWORD: str | None = os.environ.get('PROXMOX_PASSWORD')
|
||||||
|
|
||||||
|
|
||||||
def wait_status(funcs: List[Callable], status: str):
|
def wait_status(funcs: list[Callable[[], dict[str, str]]], status: str, sleep_time: float = 60) -> None:
|
||||||
statuses = [False] * len(funcs)
|
statuses = [False] * len(funcs)
|
||||||
while not all(statuses):
|
while not all(statuses):
|
||||||
logger.debug(statuses)
|
logger.debug(statuses)
|
||||||
sleep(5)
|
sleep(sleep_time)
|
||||||
for i in range(len(funcs)):
|
for i in range(len(funcs)):
|
||||||
statuses[i] = funcs[i]()['status'] == status
|
statuses[i] = funcs[i]()['status'] == status
|
||||||
|
|
||||||
@ -108,8 +108,9 @@ def main() -> None:
|
|||||||
proxmox.nodes(node).tasks(upid_master).status.get,
|
proxmox.nodes(node).tasks(upid_master).status.get,
|
||||||
proxmox.nodes(node).tasks(upid_worker1).status.get,
|
proxmox.nodes(node).tasks(upid_worker1).status.get,
|
||||||
proxmox.nodes(node).tasks(upid_worker2).status.get,
|
proxmox.nodes(node).tasks(upid_worker2).status.get,
|
||||||
],
|
], # pyright: ignore
|
||||||
'stopped'
|
'stopped',
|
||||||
|
sleep_time=60,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info('Cloning completed!')
|
logger.info('Cloning completed!')
|
||||||
@ -123,8 +124,9 @@ def main() -> None:
|
|||||||
proxmox.nodes(node).qemu(vm_ids['master']).status.current.get,
|
proxmox.nodes(node).qemu(vm_ids['master']).status.current.get,
|
||||||
proxmox.nodes(node).qemu(vm_ids['worker1']).status.current.get,
|
proxmox.nodes(node).qemu(vm_ids['worker1']).status.current.get,
|
||||||
proxmox.nodes(node).qemu(vm_ids['worker2']).status.current.get,
|
proxmox.nodes(node).qemu(vm_ids['worker2']).status.current.get,
|
||||||
],
|
], # pyright: ignore
|
||||||
'running'
|
'running',
|
||||||
|
sleep_time=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
sleep(40)
|
sleep(40)
|
||||||
|
Loading…
Reference in New Issue
Block a user