A little python project to make your heroku app alive forever without being concerned about dyno hours. You do not need to bother adding a credit card to get more dyno hours.
ℹ️ I know this is just a petty trick, but at least, it's useful for me. If you use another service than heroku, or you have credit cards to get your heroku accounts verified, or you don't like what I'm doing, you may stop reading this and leave, thank you. |
---|
The main idea is to use two accounts (yeah, you need 2 of them to make this work) with two same apps and shift the dyno every 1st and 15th of a month.
There are two methods you can use, No loop and Autoloop.
I recommend you to use no loop method with Github Actions because it's less complicated and less obstructive.
There are two Github Actions workflows that have been set with cron jobs. They will run automatically at 00:00 UTC 1st and 15th of a month and when they're running, they will switch the dynos respectively.
Every 10 mins, the script will check if today is either 1st or 15th of a month. If it's true, then it'll switch the dynos respectively.
- This may make your app restart once more at 1st and 15th of the month though (besides the usual 24h restart in heroku free tier).
- You need to deploy to both apps at first, and whenever there's a change you want to make to the app, you need to deploy to both apps too. Patience is really needed for that.
- Only for autoloop method: The primary app's dyno will be automatically activated every 10 minutes for the entire day of 1st of a month and the secondary app's dyno will be automatically activated every 10 minutes for the entire day of 15th of a month. That will be bad for you when you don't want to activate the dynos at those certain days. Deactivate this script first before doing that.
- Heroku API will be called more at 1st and 15th of a month with this script. At least, there'll be 18 API calls per hour per acc. It's not that many and it's acceptable, but please note this if you are planning to use heroku API calls.
Someone already made a similar concept and it's easier to apply than this script.
https://heroku.viperadnan.gq/duo
You can just add your app names and heroku API keys there, but use it with your own risk.
You may use this script if you don't trust the site your credentials, as this repo is open source and you can see what's written in the code.
Before you use this, know that problems may occur whenever because of my poor coding skill, so please, if you have time, check my code in script.py
for Autoloop method and script_noloop.py
for No loop method, report any error in Issues, and do pull request (or just make your own fork with your own features if it's personal). That will be highly appriciated.
Platform | Method | Deployment | Notes |
---|---|---|---|
Github Actions (Recommended) |
No Loop | Click here | Recommended deployment platform as "No loop" method won't be intrusive. |
Heroku | Autoloop | Deploy to Heroku | • You can deploy this script to another Heroku account. • Unverified Heroku account works too, no need for 1000 dyno hours as this script will only run effectively on 1st (when dyno hours reset) and 15th of a month. • Add additional variables later by yourself. |
Railway | Autoloop | 1. Fork this repo 2. Set the variables 3. Connect the repo to Railway via Github deployment |
Another free PaaS like Heroku with always-on apps feature. |
FIRST_PROCESSTYPE
is the process type of your app, you can useweb
,worker
or something else. Check it in the Resources tab of your heroku app.FIRST_A_APPNAME
is the app name of your primary app.FIRST_A_APIKEY
is the API key of the heroku account your primary app is in. Check it in your heroku settings, in the last of the page.FIRST_B_APPNAME
is the app name of your secondary app.FIRST_B_APIKEY
is the API key of the heroku account your secondary app is in. Check it in your heroku settings, in the last of the page.
The script supports up to 5 pair of apps simultaneously. You may add these vars if you need it.
SECOND_PROCESSTYPE
, SECOND_A_APPNAME
, SECOND_A_APIKEY
, SECOND_B_APPNAME
, SECOND_B_APIKEY
THIRD_PROCESSTYPE
, THIRD_A_APPNAME
, THIRD_A_APIKEY
, THIRD_B_APPNAME
, THIRD_B_APIKEY
FOURTH_PROCESSTYPE
, FOURTH_A_APPNAME
, FOURTH_A_APIKEY
, FOURTH_B_APPNAME
, FOURTH_B_APIKEY
FIFTH_PROCESSTYPE
, FIFTH_A_APPNAME
, FIFTH_A_APIKEY
, FIFTH_B_APPNAME
, FIFTH_B_APIKEY
If you need more than 5 apps, you can extend the code as much as you want, or if you don't know how to do it, just deploy more of this script, it works too.
- Me who happened to have written this very little and simple script (My telegram and my another telegram acc)
- https://pypi.org/project/heroku3/ for allowing us using heroku API with python
- Many userbot repos that I looked to see how heroku3 module works
- @ZekXtreme for Github Actions deployment concept
- And many others that I can't say all of them here