3

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 :)

  • yes I believe so. if you haven't done so already, you can get a free server for a year with amazon aws, maybe it's better suited to your app – xShirase Nov 30 '16 at 12:02

1 Answers1

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.

Basim Hennawi
  • 2,651
  • 3
  • 19
  • 31
  • 1
    If the instance starts sleeping, the `setTimeout` will never be executed though. – Damien MATHIEU Nov 30 '16 at 12:30
  • Yes, you're right, @DamienMATHIEU so to avoid this and keep the server up and running 24/7, check this: http://stackoverflow.com/questions/40646858/avoid-heroku-server-from-sleeping Damo – Basim Hennawi Nov 30 '16 at 12:35
  • So the reality is, a reminder function would not work unless I was always running the bot? –  Nov 30 '16 at 15:24
  • Just if your time to wait before executing the code (in setTimeout) is more than 30 minutes. – Basim Hennawi Nov 30 '16 at 15:26