Skip to content

CLI-Tool that manages your Heroku apps running on free dynos and using a cron job pings them every 15 minutes so they never go to sleep

License

Notifications You must be signed in to change notification settings

DanNduati/Heroku_idler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Heroku Idler

Description

Heroku Idler is a python typer cli application that manages a url list of your heroku applications running on free dynos you can then ping these apps every 15 minutes so they never go to sleep and avoid long dyno wake-up time. The CLI is based on Typer, a modern and versatile library for creating CLI applications.

Prerequisites

Setup

Click to expand!

Clone repository

$ git clone https://github.com/DanNduati/Heroku_idler.git

Install dependencies

If you have pipenv installed use:

$ pipenv install

Otherwise you can use the requirements.txt file:

# create virtualenvironment and activate it
$ python -m venv venv
$ source venv/bin/activate
# install dependencies
$ pip install -r requirements.txt

Usage

Click to expand!

The application provides the following commands to initialize the app,add and remove urls and ping the urls:

Command Description
init Initialises the application’configuration and JSON storage
add [URL] Adds a new Heroku app URL
list Lists all the URLs added
remove [URL_ID] Removes a URL from storage by id
ping Pings the URLs present in the JSON storage

Scheduling

Click to expand!

Since apps using free web dynos sleep after 30 minutes of inactivity I use the Cron job scheduler to run the ping cli command of the application that pings my applications every 15 minutes

⚠️ The cron service is only available for Unix-base systems! checkout the windows equivalent to a cron job called a scheduled task

Scheduling the worker

Each user in a Unix system has the option to set up scheduled commands that are executed by the system in a "crontab" (cron table) file. The crontab command is used to open a text editor on the user's crontab file:

$ crontab -e

The crontab -e command will start a text editor on the user's crontab file, which will initially be empty, aside from some explanatory comments. A scheduled job is given in the crontab file as a line with six fields. The first five fields are used to set up the run scheduled for the job. The sixth and last field is the command to run. You can configure multiple jobs, each with its own schedule by writing multiple lines in the crontab file.

┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23) 
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
│ │ │ │ │                                       7 is also Sunday on some systems)
│ │ │ │ │
│ │ │ │ │
* * * * *  command to execute

To run the cli ping command at every 15th minute past every hour from 6am to midnight (maintain the 18 hr quota). add this to your crontab file:

*/15 6-23,0 * * * cd <path to cli application> && <path to your virtual environment python executabl> -m herokuidler ping

In my case the worker runs on my raspberry pi it has way better uptime than my laptop :):

*/15 6-23,0 * * * cd /home/pi/Desktop/heroku_idler && /home/pi/.local/share/virtualenvs/heroku_idler-Y8-KEVQ5/bin/python -m herokuidler ping

pidler

But there's a catch here

Personal accounts are given a base of 550 free dyno hours each month. In addition to these base hours, accounts which verify with a credit card will receive an additional 450 hours added to the monthly free dyno quota. This means you can receive a total of 1000 free dyno hours per month, if you verify your account with a credit card.

So add your billing information and just like that you have 1000 hours of free dyno use a month!

Do the math: 31 days x 24 hours = 744 hours which is less than the 1000 hrs so we can have a free dyno that runs all the time for free to do what we want and still have other apps that use the remainder!

Built with

References

Todo

  • Logging
  • Add a sleep functionality for known low-use periods (ie, overnight) lol to manage quota for many apps

License

license

About

CLI-Tool that manages your Heroku apps running on free dynos and using a cron job pings them every 15 minutes so they never go to sleep

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages