Heroku 上的 Node.js 应用程序不会从空闲状态唤醒

标签 node.js heroku

<分区>

我在单个 Heroku web dyno 上有一个简单的 node.js 应用程序,并且 1 个多月没有改变。最近,我发现该应用程序没有按照 Heroku 文档(https://devcenter.heroku.com/articles/dynos#the-dyno-manager)从空闲状态返回。

相反,我的日志显示没有 Heroku 尝试在接收到 HTTP 请求时取消空闲并且应用程序返回 503 错误:

2014-06-08T08:07:22.736817+00:00 heroku[web.1]: State changed from up to down
2014-06-08T08:07:22.736356+00:00 heroku[web.1]: Idling
2014-06-08T08:07:27.844277+00:00 heroku[web.1]: Process exited with status 143
2014-06-08T08:07:26.009475+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2014-06-08T16:37:36.565924+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=brisksoft.herokuapp.com request_id=5e7040c6-fe3b-44b1-bf99-fa0214df9e5c fwd="174.21.203.228" dyno= connect= service= status=503 bytes=
2014-06-08T16:37:36.773503+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=brisksoft.herokuapp.com request_id=92627039-51f6-4a99-bafa-2c6f3a96d5ea fwd="174.21.203.228" dyno= connect= service= status=503 bytes=

我知道通过 New Relic 和 Pingdom 可以防止休眠的自动解决方法,但我更愿意实际解决这个问题并让 Heroku dyno 的行为如文档所述。

我的 package.json 是:

{
  "name": "agent-node",
  "version": "0.0.1",
  "dependencies": {
    "elementtree": "^0.1.6",
    "request": "^2.27.0",
  },
  "scripts": {
    "start": "node index.js"
  },
  "description": "Node.js application for Job Agent",
  "main": "index.js",
  "devDependencies": {},
  "repository": {
    "type": "git",
    "url": "https://github.com/brenbob/nodejs"
  },
  "author": "Brenden West",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/brenbob/nodejs/issues"
  },
  "homepage": "https://github.com/brenbob/nodejs"
}

Index.js 是:

// index.js
var server = require("./server");

server.start();

和 server.js:

var http = require("http");
var url = require('url'); 
var api = require("./api");

function start() {
  function onRequest(request, response) {
    var pathname = url.parse(request.url).pathname;
    switch(pathname) {
    case '/getjobs':
        api.getjobs(request, response);

    break;
    default:
        response.writeHead(200, {"Content-Type": "text/plain"});
        response.write("Hello World");
        response.end();
    }
  }

  http.createServer(onRequest).listen(process.env.PORT || 8888);
  console.log("Server has started.");
}

exports.start = start;

最佳答案

这似乎与怠速无关。您的应用程序从空闲状态返回时崩溃。它在本地运行吗?

关于Heroku 上的 Node.js 应用程序不会从空闲状态唤醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24108682/

相关文章:

django - Heroku:如何通过 navicat 连接数据库

node.js - 使用服务器端渲染的最佳方式

javascript - this.property 在 nodejs 中返回 undefined

mysql - 使用sequelize的sequelize-自动关系问题

scala - 从 Heroku 上正在 Play 的文件中读取

angularjs - 使用 generator-sql-fullstack 在 heroku 上拒绝连接

javascript - 使用 Joi 验证时剥离未知键

javascript - 有没有办法找到匹配两个不同填充的文档并在 findOne() 中获取他的文档?

python - Heroku 和 OpenCV 与 Python

node.js - Heroku Node.js 错误,代码=H10 desc ="App crashed"