带有npm请求的heroku超时

时间:2017-02-20 23:18:28

标签: node.js heroku cron request

我有一份工作,我通过node-cron运行,它使用请求从网站获取数据,解析数据并将新记录插入数据库。虽然一切正常,但它获取数据(只有200字节左右),解析它,创建记录并保存它,我收到超时错误,所以它再次尝试,最终运行5次,每30秒一次,所以我最终在数据库中有5条新记录。它不是正在运行的cron作业,它只运行一次。

这就是它的名字:

new CronJob('00 03 15 * * *', function() {Parse.Cloud.run("download", {"type" : "mm"});console.log("running mm");}, null, true, 'America/Los_Angeles');

以下是代码:

Parse.Cloud.define("download", function(req, status) {
var date = new Date();
var drawDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0)
drawDate.setUTCHours(drawDate.getUTCHours() - 8);

var month = ("0" + (drawDate.getMonth() + 1)).slice(-2);
var day = ("0" + drawDate.getDate()).slice(-2);

var type = req.params["type"];
//var URL = baseURL + type + "/" + drawDate.getFullYear() + "-" + month + "-" + day + ".html";
var URL = baseURL + type + "/" + drawDate.getFullYear() + "-" + "02" + "-" + "17" + ".html"

console.log("url is " + URL)

request.get(URL, function (error, resp, body) {
        if (!error && resp.statusCode == 200) {
            console.log("in request")

            var bodyString = body.toString('utf8', 0);
            var items = bodyString.split(";");

            var MyClass = Parse.Object.extend("Draw");
            var draw = new MyClass();
            draw.set("drawDate", drawDate);
            draw.set("type", type);

            // set some other fields...
            draw.save(null, { useMasterKey: true }).then(
                function(success) {
                    console.log("Saved draw for date:" + drawDate.toString());
                },
                function(error) {
                    console.log("Error " + error + "saving pb draw for date:" + drawDate.toString());
                }
            )
        }
     }
)
})

以下是我收到的错误消息:

at=error code=H12 desc="Request timeout" method=POST path="/parse/functions/downloadLotteryDraw" host=poolcaptain.herokuapp.com request_id=98481059-9cc2-4f66-b624-390775b66283 fwd="54.211.8.255" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0

我不知道为什么一切似乎都正确执行,但我得到了这些超时。

任何人都知道我在这里做错了吗?

0 个答案:

没有答案