[英]boto3 waiter for ECS ServicesStable
I am using boto3 to deploy my ECS services.我正在使用 boto3 来部署我的 ECS 服务。 I have added the boto3 waiter for ECS as:
我已将ECS 的 boto3 服务员添加为:
ecs_client = boto3.client('ecs', config=my_config)
waiter = ecs_client.get_waiter('services_stable')
waiter.wait(
cluster="myCluster",
services=["myService"],
WaiterConfig={
'Delay': 15,
'MaxAttempts': 60
}
)
print("Service is in steady state.")
The above ECS waiter works perfectly , but my ECS service takes about 5 minutes to be in running state and while executing the boto3 script, we had to wait 5 minutes with blank terminal .上面的 ECS 服务员工作得很好,但是我的 ECS 服务需要大约 5 分钟才能运行 state 并且在执行 boto3 脚本时,我们不得不在空白终端上等待 5 分钟。
Is it possible to print some message in terminal at fixed interval until the waiter is complete?是否可以在服务员完成之前以固定的时间间隔在终端中打印一些消息?
Any suggestions are appreciated.任何建议表示赞赏。
Thanks.谢谢。
A quick review of thewaiter code shows no functionality for logging status as you wait to complete.快速查看服务员代码显示在您等待完成时没有记录状态的功能。 You'll need to create your own code for this functionality.
您需要为此功能创建自己的代码。
You can run a separate thread that prints messages like below:您可以运行一个单独的线程来打印如下消息:
import time
import threading
import boto3
ecs_client = boto3.client('ecs', config=my_config)
waiter = ecs.get_waiter('services_stable')
def waiter_caller(cluster_name, service_name):
try:
waiter.wait(
cluster=cluster_name,
services=[
service_name,
],
WaiterConfig={
'Delay': 15,
'MaxAttempts': 60
}
)
except Exception as e:
print('Deploy failed', e)
t = threading.Thread(target=waiter_caller, args=("myCluster", "myService"))
t.start()
while t.is_alive():
print("Waiting for service deployment...")
time.sleep(15)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.