問題
我的問題是,當嘗試在 heroku 上部署機器人時,我得到 r10 錯誤啟動超時,但它在本地運行時有效,我似乎無法找到修復它
heroku 日志
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed
我的代碼
process.env.NTBA_FIX_319 = 1
const TelegramBot = require('node-telegram-bot-api')
require('dotenv').config()
const token = process.env.TOKEN
const myInfo = process.env.INFO
const error = process.env.ERROR
const git = process.env.GIT
const bot = new TelegramBot(token, { polling: true })
bot.on('message', (msg) => {
const chatId = msg.chat.id
const name = msg.chat.first_name
const { text } = msg
if (text === '/start' || text === '/help') {
bot.sendMessage(chatId, `Hi ${name}! These are the commands below:`, {
reply_markup: {
keyboard: [
[
{ text: '/start' },
{ text: '/about' },
{ text: '/links' },
{ text: '/help' },
],
],
resize_keyboard: true,
one_time_keyboard: true,
},
})
} else if (text === '/about') {
bot.sendMessage(chatId, `${myInfo}`)
} else if (text === '/links') {
bot.sendMessage(chatId, `${git}`)
} else {
bot.sendMessage(chatId, `${error}`)
}
})
Dockerfile
FROM node:16.13.2-alpine
WORKDIR /Bot1
ENV PORT 88
COPY package.json /Bot1/package.json
RUN npm install
COPY . .
CMD ["node", "app.js"]
部署機器人的命令
- heroku 容器:推送網路
- heroku 容器:發布網路
uj5u.com熱心網友回復:
您已將代碼部署為web行程。web行程偵聽 HTTP 請求,并且必須在啟動后不久系結到運行時提供的埠。
由于您的機器人不回應 HTTP 請求,因此不應將其部署為web行程。此類行程的通用名稱是worker.
首先,洗掉web您已經部署的容器:
heroku container:rm web
現在,將您的代碼重新部署為一個worker行程:
heroku container:push worker
heroku container:release worker
完成此操作后,您可能需要縮放測功機。就像是
heroku ps:scale worker=1
應該做的伎倆。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/428152.html
標籤:节点.js heroku 部署 运行时错误 电报机器人
上一篇:模型不保存重繪令牌
