Skip to content

Instantly share code, notes, and snippets.

@keidrun
Created April 17, 2018 09:17
Show Gist options
  • Select an option

  • Save keidrun/71aa61db28d8c17d992aad50ae8a563f to your computer and use it in GitHub Desktop.

Select an option

Save keidrun/71aa61db28d8c17d992aad50ae8a563f to your computer and use it in GitHub Desktop.
Clock process as Docker container to prevent idling for free dyno on Heroku
const axios = require('axios');
const HEROKU_APP = 'my-herokuapp';
const INTERVAL_MSEC = 10 * 60 * 1000; // every 10 minutes
setInterval(async () => {
try {
const response = await axios.get(`http://${HEROKU_APP}.herokuapp.com`);
console.log(response.status, heroku_app);
} catch (error) {
console.log(error.response.status, heroku_app);
}
}, INTERVAL_MSEC);
FROM node:9.11.1-alpine
LABEL maintainer="Keid"
RUN mkdir /app
WORKDIR /app
RUN npm install -g [email protected]
RUN chmod +x /usr/local/bin/yarn
COPY package.json package.json
COPY yarn.lock yarn.lock
RUN yarn install \
&& mv node_modules /node_modules
COPY clock.js clock.js
CMD node clock.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment