避免使用heroku服务器进行睡眠 [英] Avoid heroku server from sleeping

查看:1287
本文介绍了避免使用heroku服务器进行睡眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Heroku 服务器上托管了一个网站(我是Heroku btw的新手) ),并且因为它位于免费软件包之下,所以它在 30m的不活动状态之后休眠,并且在用户点击时再次启用它,大约需要7秒才能< npm run start 成功。



我正在考虑运行nodejs作业或每29米打开一次网站的内容,睡觉,最初,我得到了这样的东西:

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

注意:这只是在浏览器中打开它,但不会处理关闭它。 ,做这个解决方法是否合法?

  • 其次,如果是,什么是t他最好的方法来实现这一点?
  • 只要你愿意,无论如何都可以随意使用。
    请注意,您每月分配的免费动态小时数为有限。
    如果您使用信用卡验证了您的Heroku帐户,则每个月有1000个免费的测试小时,这足以让一个免费的网络测试仪永远永远不睡觉。
    一个非常简单的方法就是配置一个 New Relic附加组件为您的应用程序(使用免费的New Relic计划),您可以轻松配置定期ping您的Heroku应用程序。
    有关防止您的Heroku应用程序闲置的其他方法,请参阅这里


    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?

    解决方案

    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.

    这篇关于避免使用heroku服务器进行睡眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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