Avoid heroku server from sleeping

故事扮演 提交于 2019-11-26 23:03:28

问题


I got a website hosted on a Heroku server (i'm a new to Heroku btw), and as it's under the free package, it sleeps after 30m of inactivity, and to put it in action again when a user hits it, it takes around 7 secs to npm run start successfully.

I'm thinking of run a nodejs job or something that open the website every 29m so that the server never sleeps, initially, I got something like this:

(function wakeup() {
  require('open')('https://mywebsite.herokuapp.com', (err) => {
    if (err) throw err;
    console.log('Woke up!');
    setTimeout(wakeup, 1740000); //29m
  });
})()

N.B.: That just opens it in a browser, but not handling closing it.

  • First, is it legal to do this workaround?
  • Second, if yes, what's the best approach to implement this?

回答1:


It is perfectly legal to keep your free dyno awake for as long as you want, by any means at your disposal. Just note that your monthly allocation of free dyno hours is limited. If you verified your Heroku account with a credit card, you have 1000 free dyno hours per month, which is more than enough to keep a single free web dyno up "forever" without sleeping at all. A very easy way to do that is simply to configure a New Relic add-on for your app (using the free New Relic plan), which you can easily configure to ping your Heroku app periodically. For additional methods to prevent your Heroku app from idling, see here.



来源:https://stackoverflow.com/questions/40646858/avoid-heroku-server-from-sleeping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!