Git Product home page Git Product logo

herokudynoswitcher's Introduction

Heroku Dyno Switcher

๐Ÿ“‹ Description

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.

โš™๏ธ Mechanism

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.

No loop method

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.

Autoloop method

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.

โš ๏ธ Drawbacks

  • 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.

๐Ÿ‘ฉ๐Ÿปโ€๐Ÿคโ€๐Ÿ‘จ๐Ÿผ Alternative

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.

๐Ÿš€ Deployment

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.

What to do first?

You need to deploy two similar apps to two heroku accounts. If the day you deploy this script is under 15th (in UTC), only enable the dyno of the app in the first acc. If it's 15th or more than that (in UTC), only enable the dyno of the app in the second acc. Otherwise, the script won't run well in the first month (the next month will be adjusted correctly automatically).

Where to deploy this?

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.

๐Ÿฅช Variables

Required Variables

  • FIRST_PROCESSTYPE is the process type of your app, you can use web, 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.

Optional Variables

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.

๐Ÿ“ Credits and References

herokudynoswitcher's People

Contributors

l3v11 avatar tiararosebiezetta avatar

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.