我在Heroku上部署了运行正常的Twitter机器人(@Sunlight_Bot),仍然显示此错误:
日志显示错误H14,我认为这是由于我的机器人在帖子之间等待(setInterval
)时关闭了测功机,对吗?
2019-04-23T22:26:16.989176+00:00 app[api]: Release v81 created by user <user>
2019-04-23T22:26:16.989176+00:00 app[api]: Deploy ... by user <user>
2019-04-23T22:26:17.000000+00:00 app[api]: Build succeeded
2019-04-23T22:26:18.042459+00:00 heroku[worker.1]: Stopping all processes with SIGTERM
2019-04-23T22:26:18.104139+00:00 heroku[worker.1]: Process exited with status 143
2019-04-23T22:26:19.664782+00:00 heroku[worker.1]: Starting process with command `node app.js`
2019-04-23T22:26:20.333252+00:00 heroku[worker.1]: State changed from starting to up
2019-04-23T22:27:53.987454+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=<host> request_id=<id> fwd="<fwd>" dyno= connect= service= status=503 bytes= protocol=https
2019-04-23T22:27:54.206902+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=<host> request_id=<id> fwd="<fwd>" dyno= connect= service= status=503 bytes= protocol=https
尽管机器人正常运行,为什么Heroku仍然显示此应用程序错误?这是我可以/应该解决的东西吗?
这是代码。 setInterval
每六个小时调用一次tweeter()
函数。该功能从Heroku PostgreSQL数据库获取一些数据,对其进行格式化,然后将其作为一个或多个Tweets发布到Twitter。
function tweeter() {
stafferInfo = {};
tweetString = '';
let pool = new pg.Pool({
connectionString: process.env.DATABASE_URL,
ssl: true
} || config.db);
pool.connect()
.then(client => {
pgClient = client;
return pgClient.query(randomRow)
.then(res => {
stafferInfo = res.rows[0]; // (1) GET INFO FROM DB AND SET VARIABLE
// console.log(stafferInfo);
})
.catch(err => console.error('Error executing first psql query', err.stack));
})
.then(() => {
return pgClient.query(updateTweeted) // (2) UPDATE "TWEETED" COUNT
.then(res => {
// console.log(res);
})
.catch(err => console.error('Error executing second psql query', err.stack));
})
.then(() => { // (3) POST TWEET
tweetString = formatTweet(stafferInfo);
if ((`${tweetString} (data from ProPublica's Trump Town dataset)`).length <= (280)) {
tweetString += ` (data from ProPublica's Trump Town dataset)`
}
else if (tweetString.length <= 280) {
console.log(tweetString);
sendTweet(tweetString);
if (stafferInfo.linkedin_url) {
console.log(formatLinkedIn(stafferInfo));
sendTweet(formatLinkedIn(stafferInfo));
}
if (stafferInfo.resume_document_url) {
console.log(formatResume(stafferInfo));
sendTweet(formatResume(stafferInfo));
}
if (stafferInfo.financial_disclosure_url) {
console.log(formatFinancialDisclosure(stafferInfo));
sendTweet(formatFinancialDisclosure(stafferInfo));
}
if (stafferInfo.ethics_waiver_url) {
console.log(formatEthicsWaiver(stafferInfo));
sendTweet(formatEthicsWaiver(stafferInfo));
}
}
else {
console.log(`Tweet is longer than 280 characters: ${tweetString}`);
}
})
.catch(err => {
console.error('Error acquiring client: ', err.stack); // IF ERROR THROW TO CONSOLE
})
.finally(() => { // EITHER WAY SHUT DOWN CLIENT & POOL AFTER
if (pgClient) {
pgClient.release();
}
pool.end(); // pool shutdown
});
}
// tweeter(); // For testing
setInterval(tweeter, 6*60*60*1000);
答案 0 :(得分:1)
您的漫游器不会启动HTTP服务器,因此您不应期望它会响应请求。
如果您想让漫游器响应HTTP请求,则可以安装express,并使它以某种状态响应。首先安装express
npm install express
然后将其添加到您的漫游器中:
const express = require('express');
const app = express();
const port = 3000;
let tweet_count = 0;
// Insert your bot here
// And modify it to increment `tweet_count` when it sends a msg
app.get('/', (req, res) => res.send(`Twitter bot is up and running! Tweets sent: ${tweet_count}`));
app.listen(port, () => console.log(`Twitter bot http server listening on port ${port}!`));