Will setTimeout use Heroku free dyno hours?

自作多情 提交于 2021-02-08 04:50:04

问题


I have a bot with a command that allows the user to input a message separated with a dash and then a specified time, this is then passed to the bot and the bot reminds the user with the message after the specified amount of time has passed.

function reminder(msg) {
    const message = msg.content.replace(this.prefix+this.name+" ","");
    const params = message.split("-");
    setTimeout(() => {
        msg.channel.sendMessage(params[0]);
    }, (parseInt(params[1])*1000));
}

I intend to run this bot on Heroku, but since I'm just a teenager and this is a hobby for me I have to use the free dyno hours that Heroku gives me every month. If someone uses this function of the bot will the timing mechanism of setTimeout keep my dynos enabled and use the free dyno hours?

Edit: If you believe there is a better free alternative to Heroku that any of you know of that would be great :)


回答1:


Yes and no.

Let's assume the logic in setTimeout will be running after every less than 30 minutes, so YES the heroku server will be still awake, so it'll be using the free dyno hours.

But if the message to be sent after more than 30 minutes, let's say one hour, so if there is no any requests hitting your server in this period , your server will sleep after 30m of inactivity, so NO as long as no incoming requests.

Read more about Heroku free dyno hours, here.




回答2:


You can try this: http://neversleep.ml

It watches your server and will send notification emails if it crashes.



来源:https://stackoverflow.com/questions/40887833/will-settimeout-use-heroku-free-dyno-hours

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