cha*_*198 3 amazon-web-services amazon-ecs aws-fargate
我有一个 Fargate 服务,其中一个任务运行容器。因此,我的容器是一个定制的管道,它基于 SQS 计数运行。因此,如果所有记录都已处理,那么我会停止容器中的管道。那么,我想知道的是,我可以将服务的所需计数设置为 0,而不是停止管道吗?(该服务是该容器任务的父级)
是的,一旦该过程完成,您可以将欲望计数设置为零,但您需要考虑一些事情。
例如 Dockerfile
FROM node:alpine
RUN apk add --no-cache python py-pip
RUN pip install awscli
RUN aws --version
WORKDIR /app
COPY app.js .
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT /entrypoint.sh
Run Code Online (Sandbox Code Playgroud)
将处理 Nodejs 进程的入口点,并在 Nodejs 进程从 SQS 完成时将服务计数设置为 0。
#!/bin/sh
# start the node process, but it should exit once it processes all SQS
node app.js
# once process is done, we are good to scale down the service
aws ecs update-service --cluster my-cluster --region us-west-2 --service my-http-service --desired-count 0
Run Code Online (Sandbox Code Playgroud)
1 分钟后退出的示例节点进程,app.js
function intervalFunc() {
console.log('Container will stop in 1 minutes');
}
setInterval(intervalFunc, 1500);
setTimeout((function() {
return process.exit(0);
}), 60000);
Run Code Online (Sandbox Code Playgroud)
所以Docker镜像起着重要的作用,节点进程应该退出,否则它会继续运行。
| 归档时间: |
|
| 查看次数: |
3730 次 |
| 最近记录: |