问题描述
我有一个带有命令的机器人,该命令允许用户输入用破折号分隔的消息,然后输入指定的时间,然后将其传递给机器人,机器人在指定的时间后用消息提醒用户过去了.
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));
}
我打算在 Heroku 上运行这个机器人,但由于我只是一个青少年,这对我来说是一个爱好,我必须使用 Heroku 每个月给我的免费 dyno 小时.如果有人使用了bot的这个功能,setTimeout的计时机制会不会让我的dynos保持开启并使用免费的dyno小时?
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?
如果你相信有一个更好的免费替代 Heroku 替代你知道那会很棒:)
If you believe there is a better free alternative to Heroku that any of you know of that would be great :)
推荐答案
是和否.
假设 setTimeout 中的逻辑将在每不到 30 分钟 后运行一次,因此 是heroku 服务器仍将处于唤醒状态,因此它将使用免费测功小时.
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.
但是如果消息在超过 30 分钟后发送,比如说一小时,那么如果在此期间没有任何请求访问您的服务器,您的服务器将在 30m 不活动后休眠,所以 NO 只要没有传入请求.
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.
在此处阅读有关 Heroku 免费 dyno 时间的更多信息.
Read more about Heroku free dyno hours, here.
这篇关于setTimeout 会使用 Heroku 免费测功小时吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!