Skip to content

Commit

Permalink
Merge pull request #8 from dwyl/heroku-to-fly#7
Browse files Browse the repository at this point in the history
[PR] Adds CI, upgrades dependencies and changes scope to `fly.io`
  • Loading branch information
nelsonic authored Mar 13, 2024
2 parents 07c1f39 + b35acde commit 4d46173
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 57 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
time: "17:00"
timezone: Europe/London
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Elixir CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Build and test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.16.0' # Define the elixir version [required]
otp-version: '26.2.1' # Define the OTP version [required]

- name: Install dependencies
run: mix deps.get

- name: Run Tests
run: mix coveralls.json
env:
MIX_ENV: test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
52 changes: 22 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Easily ping (wake) an idle Heroku App from slumber.

[![Build Status](https://img.shields.io/travis/dwyl/ping/master.svg?style=flat-square)](https://travis-ci.org/dwyl/ping)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/dwyl/ping/ci.yml?label=build&style=flat-square&branch=master)
[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/ping/master.svg?style=flat-square)](https://codecov.io/github/dwyl/ping?branch=master)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/ping/issues)
[![HitCount](https://hits.dwyl.com/dwyl/ping.svg)](https://github.com/dwyl/ping)
Expand All @@ -15,10 +15,14 @@ Easily ping (wake) an idle Heroku App from slumber.

## Why? 🤷

We have _several_ demo/example/tutorial Apps deployed to Heroku. <br />
Apps on the "free" tier
go to sleep after **30 minutes** of inactivity. <br />
see: https://devcenter.heroku.com/articles/free-dyno-hours
We have _several_ demo/example/tutorial Apps deployed in services like [`Heroku`](https://www.heroku.com/) or [`Fly.io`](https://fly.io/).
In some of these (and other) services,
on their "free" tier,
apps go to sleep after a period of inactivity.

see:
- https://devcenter.heroku.com/articles/free-dyno-hours
- https://fly.io/docs/apps/autostart-stop/

In order to wake them,
we wrote a few lines of code that can be added to any
Expand All @@ -28,44 +32,36 @@ So the app is ready to go by the time the person
_reading_ the `README.md` clicks on the link. 🔗

We had implemented the "wake from sleep" endpoint
several times in our Heroku Apps,
most recently in our
[`email`](https://github.com/dwyl/email/blob/b4c2c4f4d96773c326cf3fa8cd4838973c9a78f5/lib/app_web/controllers/sent_controller.ex#L113-L170)
app.
several times in our Apps
(e.g. see [`dwyl/email`](https://github.com/dwyl/email/blob/b4c2c4f4d96773c326cf3fa8cd4838973c9a78f5/lib/app_web/controllers/sent_controller.ex#L113-L170))

After copy-pasting the code a couple of times,
we decided to make it a DRY reusable package
that we can use in our _next_ app(s)!

<br />

## What? 💡

An easy way for us to wake our Heroku demo apps.
An easy way for us to wake our Elixir apps
when deployed in cloud services like `Fly.io`.

Particularly useful when you want to pre-emptively
wake your suspended/sleeping/inactive deployed application
when people read your project's `README`.

> Note: our use case for this module is "just in time" waking of Heroku dynos. <br />
If you need your "Free" Heroku app to be _always_ awake
or awake during specific times of day,
consider _combining_ the `ping` package with a CRON job.
You can use a _free_ service such as: https://cron-job.org
as described by [Mahdhi Rezvi](https://github.com/Mahdhir) in:
https://medium.com/better-programming/keeping-my-heroku-app-alive-b19f3a8c3a82

<br />

## Who? 👤

This package is for anyone building
an Elixir/Phoenix app deployed to Heroku.
an Elixir/Phoenix app that is deployed in services that allow you to run full-stack applications
like `Fly.io`.

<br />

# How? 💻

Add `ping` to your Phoenix App
and use it to wake your Heroku App in 4 easy steps:
and use it to wake your App in 4 easy steps:

<br />

## 1. Installation 📝

Expand Down Expand Up @@ -96,7 +92,6 @@ get "/ping", PingController, :ping
e.g:
[`lib/app_web/router.ex#L21`](https://github.com/dwyl/phoenix-content-negotiation-tutorial/blob/909c80e4dd23d99589cd13c9ecb5fee1b9575c71/lib/app_web/router.ex#L21)

<br />

## 3. Create the `ping/2` Function in your Controller

Expand All @@ -114,7 +109,6 @@ end
e.g:
[`lib/app_web/controllers/ping_controller.ex#L5-L7`](https://github.com/dwyl/phoenix-content-negotiation-tutorial/blob/909c80e4dd23d99589cd13c9ecb5fee1b9575c71/lib/app_web/controllers/ping_controller.ex#L5-L7)

<br />

You can either create a brand new controller,
or use an existing one if you prefer. <br />
Expand Down Expand Up @@ -143,7 +137,7 @@ e.g:
[`test/app_web/controllers/ping_controller_test.exs#L5-L10`](https://github.com/dwyl/phoenix-content-negotiation-tutorial/blob/909c80e4dd23d99589cd13c9ecb5fee1b9575c71/test/app_web/controllers/ping_controller_test.exs#L5-L10)


## 4. Add a `GIF` to the `README.md` of the Heroku App
## 4. Add a `GIF` to the `README.md` of the App

Add an image linking to the endpoint of the App
to the `README.md` file:
Expand All @@ -163,16 +157,14 @@ so it's both minimal in size
to minimise response time
and _invisible_ to the person.
The idea is just to make the most basic HTTP request
to the Heroku app in order to wake it.
to the app in order to wake it.
We don't actually care what is returned.
But we don't want it to `404`
so the person reading the `README.md`
doesn't see an error in their console/browser.





Docs available at
[https://hexdocs.pm/ping](https://hexdocs.pm/ping).
But there's really not much to it.
12 changes: 6 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Ping.MixProject do
def project do
[
app: :ping,
version: "1.1.0",
version: "2.0.0",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand All @@ -24,7 +24,7 @@ defmodule Ping.MixProject do
[
files: ~w(lib/ping.ex LICENSE mix.exs README.md),
name: "ping",
licenses: ["GNU GPL v2.0"],
licenses: ["GPL-2.0-or-later"],
maintainers: ["dwyl"],
links: %{"GitHub" => "https://github.com/dwyl/ping"}
]
Expand All @@ -41,14 +41,14 @@ defmodule Ping.MixProject do
defp deps do
[
# Plug helper functions: github.com/elixir-plug/plug
{:plug, "~> 1.12.1"},
{:plug, "~> 1.15.3"},

# Testing Wildcard Route Handler in a Phoenix App:
{:jason, "~> 1.2.2", only: [:dev, :test]},
{:phoenix, "~> 1.6.0", only: [:dev, :test]},
{:jason, "~> 1.4.1", only: [:dev, :test]},
{:phoenix, "~> 1.7.11", only: [:dev, :test]},

# Track coverage: github.com/parroty/excoveralls
{:excoveralls, "~> 0.14.3", only: :test},
{:excoveralls, "~> 0.15.0", only: :test},

# For publishing Hex.docs:
{:ex_doc, "~> 0.25.3", only: :dev}
Expand Down
Loading

0 comments on commit 4d46173

Please sign in to comment.