首页 > 解决方案 > 在 Amazon Elastic Beanstalkd 上部署 Javascript Cron 作业和队列

问题描述

我有一个Amazon Elastic Beanstalk应用程序,目前正在运行我的NODE.JS应用程序。

我用kue.js创建了一些队列,用node-schedule创建了 Crons 。

由于我有许多命令来运行队列和 cron,我发现无法将它放在我当前的 nodejs 应用程序上。

我愿意打开一个新的应用程序,唯一的问题是我只能运行一个命令。

我真的不想打开一个单独的 ec2(未连接到我的 Elastic Beanstalk 服务)来运行所有这些。

我能做些什么来修复它?

非常感谢!

标签: javascriptnode.jsamazon-web-servicesdevopsamazon-elastic-beanstalk

解决方案


当您想使用 EB(Elastic Beanstalk)时,您可以为应用程序编写一个 docker 文件,EB 已经检测到它并询问您这是否是一个基于 docker 的项目,它会处理其余的,您只需要编写所有您需要在入口点命令 CMD 之前运行的脚本,npm start如下所示

Dockerfile

FROM node:10.13-alpine
# Sets the working directory,and creates the directory as well.
WORKDIR /app
# Install dependencies.
ADD package.json .
RUN npm install
# Copy your source code.
COPY . /app

#Run all your scripts here or simply put them to a scripts.js and run it
RUN node scripts.js

# start app
CMD ["npm", "start"]

推荐阅读