Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Last active March 19, 2023 20:54
Show Gist options
  • Save sorentwo/54d99fb2ac05cb63ea1e30aa1935b6fc to your computer and use it in GitHub Desktop.
Save sorentwo/54d99fb2ac05cb63ea1e30aa1935b6fc to your computer and use it in GitHub Desktop.
Heroku Cloud for Oban Auto Scaling
defmodule Oban.Pro.Clouds.Heroku do
@moduledoc false
@behaviour Oban.Pro.Cloud
@enforce_keys [:app, :auth_token, :dyno]
defstruct @enforce_keys
@impl Oban.Pro.Cloud
def init(opts) do
struct!(__MODULE__, opts)
end
@impl Oban.Pro.Cloud
def scale(quantity, %{app: app, auth_token: auth_token, dyno: dyno}) do
url = "https://api.heroku.com/apps/#{app}/formation/#{dyno}"
headers = [
{"Content-Type", "application/json"},
{"Accept", "application/vnd.heroku+json; version=3"},
{"Authorization", "Bearer #{auth_token}"}
]
Req.patch!(url, json: %{quantity: quantity}, headers: headers)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment