Created
January 12, 2024 11:51
-
-
Save sorentwo/90b4a427819756f7ceb72254ad53d9bb to your computer and use it in GitHub Desktop.
Gigalixir Cloud for Oban Auto Scaling
This file contains hidden or 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.Gigalixir do | |
@moduledoc """ | |
Cloud scaler for Gigalixir. | |
## Usage | |
```elixir | |
alias Oban.Pro.DynamicScaler | |
alias Oban.Pro.Clouds.Gigalixir | |
cloud_opts = [ | |
api_key: "API KEY", | |
app_name: "APP NAME", | |
email: "AUTH EMAIL" | |
] | |
plugins: [ | |
{DynamicScaler, scalers: [range: 1..3, cloud: {Gigalixir, cloud_opts}]} | |
] | |
``` | |
""" | |
@behaviour Oban.Pro.Cloud | |
defstruct [:api_key, :app, :email] | |
@impl Oban.Pro.Cloud | |
def init(opts) do | |
struct!(__MODULE__, opts) | |
end | |
@impl Oban.Pro.Cloud | |
def scale(quantity, %{api_key: api_key, app_name: app_name, email: email}) do | |
Req.put!("https://api.gigalixir.com/api/apps/#{app_name}/scale", | |
auth: {:basic, "#{email}:#{api_key}"}, | |
json: %{replicas: quantity}, | |
headers: [{"content-type", "application/json"}] | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment