Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Created January 12, 2024 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorentwo/90b4a427819756f7ceb72254ad53d9bb to your computer and use it in GitHub Desktop.
Save sorentwo/90b4a427819756f7ceb72254ad53d9bb to your computer and use it in GitHub Desktop.
Gigalixir Cloud for Oban Auto Scaling
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