Pinger - Schedule endpoint requests

May 18th 16

The problem with the Glitch Avatar updater is that it won’t call itself to update the avatar picture.

We could just add this feature into the app. However, it is something really simple that might be useful elsewhere so I decided to keep it separate.

Endpoint pinger

The app simply pings a given url on a specified time.

The configuration is exposed via environment variables so that we can easily deploy multiple times with different endpoints. For example:

  • ENDPOINT=”//www.google.com”
  • CRON_PATTERN=”

Cron patterns are tricky to remember. For help you can use a generator such as this

Node-cron is used to schedule the jobs. Cheerio to query the dom to ensure that the page has loaded properly.

onStart = ->
  url = process.env.ENDPOINT
  Request url, (err, res, html) ->
    $ = Cheerio.load(html)

new Job
  cronTime: process.env.CRON_PATTERN
  onTick: onStart
  start: true

Source is available here

Glitch Avatar Upater

Next