A little script and trick to make your heroku app run forever without being concerned about dyno hours.

Overview

Heroku Dyno Switcher

What is this?

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.
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 dyno based on the heroku app name, heroku API key, and the process type vars you have entered.

The drawbacks are:

  • 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.
  • This is basically a scheduler, so the primary app's dyno will be automatically activated every 10 minutes at 1st of a month and the secondary app's dyno will be automatically every 10 minutes at 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.

How?

Before you use this, know that I am dumb and not good at python. When I tested it, it worked. But problems may occur whenever, so please, if you have time, check my code in script.py. That will be highly appriciated.

What to do first?
You need to deploy two similar apps to two heroku accounts and only enable the dyno of the primary app.

Where to deploy/run this?

  • Another heroku account (add additional variables later by yourself)

Deploy to Heroku

  • Railway (deploy via GitHub)
  • Any PaaS hostings or always-on python hostings
  • Your own RDP/VPS

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 3 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

Credits and References

  • Me who happened to have written this very little and simple script (My telegram)
  • 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
  • And many others that I can't say all of them here
You might also like...
Python IMDB Docker - A docker tutorial to containerize a python script.

Python_IMDB_Docker A docker tutorial to containerize a python script. Build the docker in the current directory: docker build -t python-imdb . Run the

Let's learn how to build, release and operate your containerized applications to Amazon ECS and AWS Fargate using AWS Copilot.
Let's learn how to build, release and operate your containerized applications to Amazon ECS and AWS Fargate using AWS Copilot.

🚀 Welcome to AWS Copilot Workshop In this workshop, you'll learn how to build, release and operate your containerised applications to Amazon ECS and

Glances an Eye on your system. A top/htop alternative for GNU/Linux, BSD, Mac OS and Windows operating systems.
Glances an Eye on your system. A top/htop alternative for GNU/Linux, BSD, Mac OS and Windows operating systems.

Glances - An eye on your system Summary Glances is a cross-platform monitoring tool which aims to present a large amount of monitoring information thr

Automatically capture your Ookla Speedtest metrics and display them in a Grafana dashboard
Automatically capture your Ookla Speedtest metrics and display them in a Grafana dashboard

Speedtest All-In-One Automatically capture your Ookla Speedtest metrics and display them in a Grafana dashboard. Getting Started About This Code This

Manage your SSH like a boss.
Manage your SSH like a boss.

--- storm is a command line tool to manage your ssh connections. features adding, editing, deleting, listing, searching across your SSHConfig. command

A Kubernetes operator that creates UptimeRobot monitors for your ingresses

This operator automatically creates uptime monitors at UptimeRobot for your Kubernetes Ingress resources. This allows you to easily integrate uptime monitoring of your services into your Kubernetes deployments.

Nagios status monitor for your desktop.

Nagstamon Nagstamon is a status monitor for the desktop. It connects to multiple Nagios, Icinga, Opsview, Centreon, Op5 Monitor/Ninja, Checkmk Multisi

Manage your azure VM easily!

Azure-manager Manage your VM in Azure using cookies.

Comments
  • Already filled vars but it said Variables for the first app are not fully filled.

    Already filled vars but it said Variables for the first app are not fully filled.

    I already fill FIRST_PROCESSTYPE, FIRST_A_APPNAME, FIRST_A_APIKEY, FIRST_B_APPNAME, FIRST_B_APIKEY but it said Variables for the first app are not fully filled (Check telegraph link for more detail)

    https://telegra.ph/file/7e87d45e9f6302cd9b95b.jpg https://telegra.ph/file/77ce0982d031b2fbca587.jpg

    opened by alok99-git 2
  • [Github Workflow] Repetitive Code Removed. Program is dynamic now.

    [Github Workflow] Repetitive Code Removed. Program is dynamic now.

    Now on if you want to deploy 2 pair of apps then : Add TOTAL_APP_PAIRS in environment and specify how many pair of apps you want to switch (example : 2) then For app pair 1 add these environment variables : PROCESSTYPE_1 , A_APIKEY_1 ,A_APPNAME_1 ,B_APIKEY_1, B_APPNAME_1 For app pair 2 add these environment variables : PROCESSTYPE_2 , A_APIKEY_2 ,A_APPNAME_2 ,B_APIKEY_2, B_APPNAME_2

    opened by a0v0 2
  • Sanitized

    Sanitized

    Sanitized code base.

    • Removed redundant code.
    • Improved logic.
    • Merged both scripts files.

    Please check if docs need to be updated for the same, a new env is required now called TOTAL_APP_PAIRS

    opened by itszechs 0
  • railway

    railway

    image railway ban the project immediately, if I forked, so I only copy files that seems important: script, runtime, requirement, app.json, profile, dockerfile.

    please tell me what I did wrong, it just doesn't seems to be running, no log in deploy log

    opened by phyIlo 0
Owner
Tiararose Biezetta
Me noob pro max ultra 16"
Tiararose Biezetta
Define and run multi-container applications with Docker

Docker Compose Docker Compose is a tool for running multi-container applications on Docker defined using the Compose file format. A Compose file is us

Docker 28.2k Jan 8, 2023
Copy a Kubernetes pod and run commands in its environment

copypod Utility for copying a running Kubernetes pod so you can run commands in a copy of its environment, without worrying about it the pod potential

Memrise 4 Apr 8, 2022
DAMPP (gui) is a Python based program to run simple webservers using MySQL, Php, Apache and PhpMyAdmin inside of Docker containers.

DAMPP (gui) is a Python based program to run simple webservers using MySQL, Php, Apache and PhpMyAdmin inside of Docker containers.

Sehan Weerasekara 1 Feb 19, 2022
Run Oracle on Kubernetes with El Carro

El Carro is a new project that offers a way to run Oracle databases in Kubernetes as a portable, open source, community driven, no vendor lock-in container orchestration system. El Carro provides a powerful declarative API for comprehensive and consistent configuration and deployment as well as for real-time operations and monitoring.

Google Cloud Platform 205 Dec 30, 2022
This Docker container is build to run on a server an provide an easy to use interface for every student to vote for their councilors

This Docker container is build to run on a server and provide an easy to use interface for every student to vote for their councilors.

Robin Adelwarth 7 Nov 23, 2022
Helperpod - A CLI tool to run a Kubernetes utility pod with pre-installed tools that can be used for debugging/testing purposes inside a Kubernetes cluster

Helperpod is a CLI tool to run a Kubernetes utility pod with pre-installed tools that can be used for debugging/testing purposes inside a Kubernetes cluster.

Atakan Tatlı 2 Feb 5, 2022
Tools and Docker images to make a fast Ruby on Rails development environment

Tools and Docker images to make a fast Ruby on Rails development environment. With the production templates, moving from development to production will be seamless.

null 1 Nov 13, 2022
A simple python application for running a CI pipeline locally This app currently supports GitLab CI scripts

?? Simple Local CI Runner ?? A simple python application for running a CI pipeline locally This app currently supports GitLab CI scripts ⚙️ Setup Inst

Tom Stowe 0 Jan 11, 2022
Google Kubernetes Engine (GKE) with a Snyk Kubernetes controller installed/configured for Snyk App

Google Kubernetes Engine (GKE) with a Snyk Kubernetes controller installed/configured for Snyk App This example provisions a Google Kubernetes Engine

Pas Apicella 2 Feb 9, 2022
A Simple script to hunt unused Kubernetes resources.

K8SPurger A Simple script to hunt unused Kubernetes resources. Release History Release 0.3 Added Ingress Added Services Account Adding RoleBindding Re

Yogesh Kunjir 202 Nov 19, 2022