Skip to content

Instantly share code, notes, and snippets.

Last active March 19, 2023 20:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sorentwo/d6be222091db7ba3c5b50d8bcabca252 to your computer and use it in GitHub Desktop.
Fly Cloud for Oban Auto Scaling
defmodule Oban.Pro.Clouds.Fly do
@moduledoc false
@behaviour Oban.Pro.Cloud
@enforce_keys [:app_id, :auth_token, :regions]
defstruct @enforce_keys
@url ""
@query """
mutation ScaleApp($input: ScaleAppInput!) {
scaleApp(input: $input) {
delta {
@impl Oban.Pro.Cloud
def init(opts) do
struct!(__MODULE__, opts)
@impl Oban.Pro.Cloud
def scale(quantity, %{app_id: app_id, auth_token: auth_token, regions: regions}) do
headers = [
{"Content-Type", "application/json"},
{"Accept", "application/json"},
{"Authorization", "Bearer #{auth_token}"}
regions =, &%{region: &1, count: quantity})
body = %{
query: @query,
variables: %{input: %{appId: app_id, regions: regions}}
}!(@url, json: body, headers: headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment