我已经运行了一个守护程序服务器来按计划时间发布社交网络订阅源。
目前,我在运行以node.js编写的守护程序服务器时遇到问题,并使用mongodb支持表达框架。
请参阅heroku logs命令中的以下错误。
←[36m2014-11-05T12:07:26.934753+00:00 app[web.1]:←[0m Daemon worker process is online.
←[36m2014-11-05T12:07:28.147952+00:00 app[web.1]:←[0m Starting daemon server
←[36m2014-11-05T12:07:28.230621+00:00 app[web.1]:←[0m APN agent connected.
←[36m2014-11-05T12:07:27.730718+00:00 app[web.1]:←[0m Successfully connected to MongoDB
←[36m2014-11-05T12:08:27.375215+00:00 heroku[web.1]:←[0m State changed from starting to crashed
←[36m2014-11-05T12:07:23.455341+00:00 heroku[web.1]:←[0m State changed from crashed to starting
←[36m2014-11-05T12:08:26.523383+00:00 heroku[web.1]:←[0m Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
←[36m2014-11-05T12:08:26.523870+00:00 heroku[web.1]:←[0m Stopping process with SIGKILL
←[36m2014-11-05T12:08:27.369727+00:00 heroku[web.1]:←[0m Process exited with status 137
正如您所看到守护程序服务器脚本成功运行但在此之后Heroku日志显示启动超时错误。
var cluster = require('cluster')
if(cluster.isMaster){
cluster.fork()
cluster.on('online', function(worker){
console.log('Daemon worker process is online.')
})
cluster.on('exit', function(worker){
console.log('Daemon worker process has died. Booting another.')
cluster.fork()
})
} else {
var mongoose = require('mongoose')
var mongoDbURI
if(process.argv.indexOf('localdb') != -1){
mongoDbURI = 'mongodb://[IP]/[appname]'
} else {
//mongoDbURI = 'mongodb://[db url]'
mongoDbURI = '[db url]'
}
var mongoDbOptions = {}
if(process.env.MONGODB_URI)
mongoDbURI = process.env.MONGODB_URI
if(process.env.MONGODB_OPTIONS)
mongoDbOptions = JSON.stringify(process.env.MONGODB_OPTIONS)
var Agenda = require('agenda')
var agenda = new Agenda()
.database(mongoDbURI, 'daemonTasks')
.processEvery('1 minute')
//On termination of daemon, gracefully shut down jobs
function gracefulShutdown() {
agenda.stop(function() {
console.log("Shutting down daemon server")
process.exit(0)
})
}
process.on('SIGTERM', gracefulShutdown)
process.on('SIGINT' , gracefulShutdown)
var fs = require('fs-extra')
mongoose.connect(mongoDbURI, mongoDbOptions)
var db = mongoose.connection
db.on('error', function(err){
//If the database can not be connected to, die
console.error("Error connecting to MongoDB\r\n", err)
process.exit()
})
db.once('open', function(){
//Connection successful
console.log("Successfully connected to MongoDB")
//Begin loading our schema
require('./Models/models')(mongoose, function(err, models){
//Set up the agenda piece
var Agenda = require('agenda')
models.Agenda = new Agenda()
.database(mongoDbURI, 'daemonTasks')
// Connect to the Apple Push Notification Service
models.APNAgent = require('./Modules/apnAgent')(models)
if(err){
console.log("Error loading models\r\n", err)
process.exit()
}
var async = require('async')
fs.readdir('./Daemons/', function(err, files){
if(err){
console.log(err)
cb(err)
} else {
async.each(files, function(file, cb){
fs.lstat('./Daemons/' + file, function(err, stat){
if(err){
cb(err)
} else {
if(stat.isFile()){
var daemon = require('./Daemons/' + file)(models)
agenda.define(daemon.name, daemon.options, daemon.job)
cb(null)
} else {
cb(err)
}
}
})
}, function(err){
if(err){
console.log("Error starting daemon server: ", err)
return
}
console.log("Starting daemon server")
agenda.start()
})
}
})
})
})
}
我已经在网上进行了研究,发现一些解决方案表明这个问题是为了增加网络处理时间,但是在Heroku上找不到我可以设置这个值的地方。