带有Node Js的Heroku调度程序 [英] Heroku scheduler with Node Js

查看:151
本文介绍了带有Node Js的Heroku调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循这里这个答案,它的工作原理,但是当我尝试拨打我的应用程序没有任何反应我有我的主要功能在app.js称为

I've followed this answer here and it works but when I try to call my app nothing happens. I have my main function in app.js called

function start() { ... }

这是我储存在bin中的任务,我知道它在我打电话时工作:

This is my task stored in bin which I know it works when I call:

#! /app/.heroku/node/bin/node
function mytask() {
  start();
}
initScrape();
process.exit();

After: heroku run init mytask

λ heroku run init_scrape                                 
Running mytask on dyno1... up, run.5157   
/app/bin/mytask:3                                   
  start();                                               
  ^                                                      

ReferenceError: start is not defined                     
    at mytask (/app/bin/mytask:3:3)             
    at Object.<anonymous> (/app/bin/mytask:5:1)     
    at Module._compile (module.js:413:34)                
    at Object.Module._extensions..js (module.js:422:10)  
    at Module.load (module.js:357:32)                    
    at Function.Module._load (module.js:314:12)          
    at Function.Module.runMain (module.js:447:10)        
    at startup (node.js:148:18)                          
    at node.js:405:3                                     


推荐答案

您需要从定义的位置导出start,并且您的脚本需要具有 start )定义。否则它将如何知道在哪里可以找到它?

You need to export start from where it is defined and your script needs to require the file that has start() defined. Otherwise how would it know where to find it?

因此,您可能需要修改app.js并说 module.exports = start 。然后在 mytask 文件中执行此操作:

So you probably need to modify your app.js and say module.exports = start. Then in the mytask file you do this:

#! /app/.heroku/node/bin/node
var start = require('./app.js');
function mytask() {
  start();
}
initScrape();
process.exit();

这篇关于带有Node Js的Heroku调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆