简体   繁体   English

使用Node Js的Heroku调度程序

[英]Heroku scheduler with Node 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 我的主要功能在app.js中

function start() { ... }

This is my task stored in bin which I know it works when I call: 这是我存储在bin中的任务,我知道该任务在调用时起作用:

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

After: heroku run init mytask 之后: 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                                     

You need to export start from where it is defined and your script needs to require the file that has start() defined. 您需要从定义的位置导出开始,并且脚本需要使用定义了start()的文件。 Otherwise how would it know where to find it? 否则它将如何知道在哪里找到它?

So you probably need to modify your app.js and say module.exports = start . 因此,您可能需要修改app.js并说module.exports = start Then in the mytask file you do this: 然后在mytask文件中执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM