Last active
March 19, 2023 20:54
-
-
Save sorentwo/54d99fb2ac05cb63ea1e30aa1935b6fc to your computer and use it in GitHub Desktop.
Heroku Cloud for Oban Auto Scaling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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