Coder Social home page Coder Social logo

hubot-heroku-keepalive's Introduction

hubot-heroku-keepalive

A hubot script that keeps the hubot Heroku free web dyno alive.

Note that a free Heroku dyno can only run for 18 hours/day, so it will be required to sleep for at least 6 hours. Accessing your Hubot during a sleep period will wake it, but it will return to sleep after 30 minutes.

Installation

In hubot project repository, run:

npm install hubot-heroku-keepalive --save

Then add hubot-heroku-keepalive to your external-scripts.json:

[
  "hubot-heroku-keepalive"
]

Configuring

hubot-heroku-keepalive is configured by four environment variables:

  • HUBOT_HEROKU_KEEPALIVE_URL - required, the complete URL to keepalive, including a trailing slash.
  • HUBOT_HEROKU_WAKEUP_TIME - optional, the time of day (HH:MM) when hubot should wake up. Default: 6:00 (6 am)
  • HUBOT_HEROKU_SLEEP_TIME - optional, the time of day (HH:MM) when hubot should go to sleep. Default: 22:00 (10 pm)
  • HUBOT_HEROKU_KEEPALIVE_INTERVAL - the interval in which to keepalive, in minutes. Default: 5

You must set HUBOT_HEROKU_KEEPALIVE_URL and it must include a trailing slash – otherwise the script won't run. You can find out the value for this by running heroku apps:info. Copy the Web URL and run:

heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=PASTE_WEB_URL_HERE

If you want to trust a shell snippet from the Internet, here's a one-liner:

heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s | grep web.url | cut -d= -f2)

HUBOT_HEROKU_WAKEUP_TIME and HUBOT_HEROKU_SLEEP_TIME define the waking hours - between these times the keepalive will ping your Heroku app. Outside of those times, the ping will be suppressed, allowing the dyno to shut down. These times are based on the timezone of your Heroku application which defaults to UTC. You can change this with:

heroku config:add TZ="America/New_York"

Waking Hubot Up

This script will keep the dyno alive once it is awake, but something needs to wake it up. You can use the Heroku Scheduler to wake the dyno up. Add the scheduler addon by running:

heroku addons:create scheduler:standard

The scheduler must be manually configured from the web interface, so run heroku addons:open scheduler and configure it to run curl ${HUBOT_HEROKU_KEEPALIVE_URL}heroku/keepalive at the time configured for HUBOT_HEROKU_WAKEUP_TIME.

Heroku Scheduler Screenshot

Note that the Scheduler's time is in UTC. If you changed your application's timezone with TZ, you'll need to convert that time to UTC for the wakup job. For example, if HUBOT_HEROKU_WAKEUP_TIME is set to 06:00 and TZ is set to America/New_York, you'll need to set the Scheduler to run at 10:00 AM UTC.

Legacy Support

Hubot has for a long time had it's own builtin way to keep its web dyno alive, but this is an extraction of that behavior.

The legacy support uses the HEROKU_URL environment variable instead of HUBOT_HEROKU_KEEPALIVE_URL, so for forward compatability, hubot-heroku-keepalive will also use HEROKU_URL if it's present, and will also disable the legacy keepalive behavior if it's present.

Development

The best way is to use npm link and make sure to point HUBOT_HEROKU_KEEPALIVE_URL at the right place:

hubot-heroku-keepalive$ npm link
hubot-heroku-keepalive$ cd /path/to/your/hubot
hubot$ npm link hubot-heroku-keepalive
hubot$ export HUBOT_HEROKU_KEEPALIVE_URL=http://localhost:8080/
hubot$ bin/hubot

hubot-heroku-keepalive's People

Contributors

178inaba avatar abeger avatar awaxa avatar bkeepers avatar chrisvfritz avatar despairblue avatar fcarrega avatar gr2m avatar johnnaegle avatar jonathan-soifer avatar kei-s avatar kmanzana avatar kylev avatar parkr avatar technicalpickles avatar treby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hubot-heroku-keepalive's Issues

heroku: command not found

In hubot project repository, I run npm install hubot-heroku-keepalive --save , and add the hubot-heroku-keepalive to my external-scripts.json, there exists hubot-heroku-keepalive under node_modules directory, but when run heroku apps:info , it said heroku: command not found, why? Thanks!

Be more forgiving with HEROKU_URL envvar

Why not just add the trailing slash if it's not there? Further, why not just allow someone to use the app name slug?

I ask not rhetorically, but because I suspect there might be good reason :)

Accessing Hubot

I was hoping that you could help me understand your hubot heroku keepalive script a little better. I am struggling to have my hubot wake up during a sleep period (or verifying if your plugin is working at all) -- specifically, i'm not sure what you mean by "accessing your Hubot during a sleep period will wake it, but it will return to sleep after 30 minutes". Does "accessing my hubot" mean simply chatting to it -- because that has not been working for me.

Hubot not waking up

Hey guys,

Not sure if something's changed regarding how the script or heroku works but I noticed over the past while hubot has been falling asleep and then not waking up. I currently have the sleep time on the script to sleep from 22:00 to 7:00.

I have Heroku Scheduler running with the following parameters: (maybe this is conflicting with the script?)

Dyno size Frequency Last run Next due
Free Daily Nov 21 9:00 UTC Nov 22 9:00 UTC

Log:

2016-11-21T09:00:39.315430+00:00 heroku[scheduler.2640]: Process exited with status 0 2016-11-21T09:05:38.022935+00:00 app[web.1]: [Mon Nov 21 2016 05:05:38 GMT-0400 (AST)] INFO keepalive ping 2016-11-21T09:05:38.023082+00:00 app[web.1]: [Mon Nov 21 2016 05:05:38 GMT-0400 (AST)] INFO Skipping keep alive, time to rest 2016-11-21T09:10:38.022657+00:00 app[web.1]: [Mon Nov 21 2016 05:10:38 GMT-0400 (AST)] INFO keepalive ping 2016-11-21T09:10:38.022736+00:00 app[web.1]: [Mon Nov 21 2016 05:10:38 GMT-0400 (AST)] INFO Skipping keep alive, time to rest 2016-11-21T09:15:38.023198+00:00 app[web.1]: [Mon Nov 21 2016 05:15:38 GMT-0400 (AST)] INFO keepalive ping 2016-11-21T09:15:38.023269+00:00 app[web.1]: [Mon Nov 21 2016 05:15:38 GMT-0400 (AST)] INFO Skipping keep alive, time to rest 2016-11-21T09:20:38.028584+00:00 app[web.1]: [Mon Nov 21 2016 05:20:38 GMT-0400 (AST)] INFO keepalive ping 2016-11-21T09:20:38.028724+00:00 app[web.1]: [Mon Nov 21 2016 05:20:38 GMT-0400 (AST)] INFO Skipping keep alive, time to rest 2016-11-21T09:25:38.033125+00:00 app[web.1]: [Mon Nov 21 2016 05:25:38 GMT-0400 (AST)] INFO keepalive ping 2016-11-21T09:25:38.033189+00:00 app[web.1]: [Mon Nov 21 2016 05:25:38 GMT-0400 (AST)] INFO Skipping keep alive, time to rest 2016-11-21T09:30:38.037565+00:00 app[web.1]: [Mon Nov 21 2016 05:30:38 GMT-0400 (AST)] INFO Skipping keep alive, time to rest 2016-11-21T09:30:38.037409+00:00 app[web.1]: [Mon Nov 21 2016 05:30:38 GMT-0400 (AST)] INFO keepalive ping 2016-11-21T09:35:38.041859+00:00 app[web.1]: [Mon Nov 21 2016 05:35:38 GMT-0400 (AST)] INFO keepalive ping 2016-11-21T09:35:38.041911+00:00 app[web.1]: [Mon Nov 21 2016 05:35:38 GMT-0400 (AST)] INFO Skipping keep alive, time to rest 2016-11-21T09:37:28.820046+00:00 heroku[web.1]: Idling 2016-11-21T09:37:28.820566+00:00 heroku[web.1]: State changed from up to down 2016-11-21T09:37:29.429852+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2016-11-21T09:37:29.543054+00:00 heroku[web.1]: Process exited with status 0

Hubot doesn't wakeup

Hubot doesn't wakeup after going to sleep.
My config is

HUBOT_HEROKU_KEEPALIVE_URL:      https://caari.herokuapp.com/
HUBOT_HEROKU_SLEEP_TIME:         1:10
HUBOT_HEROKU_WAKEUP_TIME:        1:40
TZ:                              Asia/Karachi

Logs:

» 29 Apr 2017 01:34:04.684  102 <45>1 2017-04-28T20:34:04.324911+00:00 heroku web.1 - - Idling
» 29 Apr 2017 01:34:04.749  125 <45>1 2017-04-28T20:34:04.325568+00:00 heroku web.1 - - State changed from up to down
» 29 Apr 2017 01:34:05.201  131 <45>1 2017-04-28T20:34:05.130888+00:00 heroku web.1 - - Stopping all processes with SIGTERM
» 29 Apr 2017 01:34:05.812  124 <45>1 2017-04-28T20:34:05.430702+00:00 heroku web.1 - - Process exited with status 0
» 29 Apr 2017 02:27:02.404  104 <45>1 2017-04-28T21:27:02.008938+00:00 heroku web.1 - - Unidling
» 29 Apr 2017 02:27:02.471  131 <45>1 2017-04-28T21:27:02.009285+00:00 heroku web.1 - - State changed from down to starting

There was HTTP post request at 2:27, which started the dyno again.
I think bot should have been up at 1:40, is there something I'm missing?

Take into account Heroku's new idling policy

In the past few days, Heroku made this announcement:

Another important change has to do with dyno idling, or ‘sleeping’. While non-paid apps have always slept after an activity timeout, some apps used automatic pinging services to prevent that behavior. free dynos are allowed 18 hours awake per 24 hour period, and over the next few weeks we will begin to notify users of apps that exceed that limit

  • Heroku

How should we take this into account? set a variable for hubot's "waking hours"?

Can't set night owl schedule

I set the environment variables as follows

  • HUBOT_HEROKU_WAKEUP_TIME = '8:00'
  • HUBOT_HEROKU_SLEEP_TIME = '2:00'

but hubot puts INFO Skipping keep alive, time to rest log out and sleeps soon.
(I think this line decides the behavior.)

Does anyone know the way to avoid this problem?

Issue with running keep alive script

I am having an issue that I am hoping you might be able to give me some pointers on...

I have 4 apps set up in Heroku, each of them is a Hubot instance, that is linked to a Gitter chat room. The Hubot instance itself is working as I would expect them to, however, 2 out of the 4 applications fail to come back to life each morning. As you can see here:

image

From what I can tell, each application is configured exactly the same way, so I can't understand why two of them don't wake up.

Can you suggest anything that I can look into? Thanks!

Don't be as annoying in development

If you have this in your external-scripts.json in development without HUBOT_HEROKU_KEEPALIVE_URL or HEROKU_URL, it will log a warning every startup which is kind of annoying.

I'm open to suggestions about shushing it. Some ideas:

  • look at NODE_ENV, and don't warn during development
  • look at a new environment variable to not warn

cc hubotio/generator-hubot#25

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.