Using Heroku Scheduler with Node.js

前端 未结 6 1472
小蘑菇
小蘑菇 2020-12-07 11:14

There is literally no tutorial about using Heroku Scheduler with Node.js. Assume that I have a function called sayHello() and I would like to run it every 10 mins. Ho

6条回答
  •  甜味超标
    2020-12-07 11:40

    Following steps work in my situation.

    1. In the root folder add worker.js file.
    2. In worker.js. Write an simple function, like above. function sayHello() { console.log('Hello'); } sayHello();
    3. Go to heroku Scheduler add-ons. Click 'add new job' and type 'worker' in the field. Then set time interval and click save.

    Here are something should notice

    1. After update works setting.If using above example, you can use heroku run node worker.js to check if it work. It should be show 'Hello' in your terminal.
    2. I use express-babel starter for my node.js project.

提交回复
热议问题