-
-
Save sorentwo/a54a1e2b37123fd627cca16f07aed951 to your computer and use it in GitHub Desktop.
GCP Instance Group Manager 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.GoogleCloud do | |
@moduledoc false | |
@behaviour Oban.Pro.Cloud | |
@enforce_keys [:api_key, :instance_group_manager, :project_id, :zone] | |
defstruct @enforce_keys | |
@impl Oban.Pro.Cloud | |
def init(opts) do | |
struct!(__MODULE__, opts) | |
end | |
@impl Oban.Pro.Cloud | |
def scale(quantity, %__MODULE__{} = conf) do | |
%{ | |
project_id: project_id, | |
zone: zone, | |
instance_group_manager: instance_group_manager, | |
api_key: api_key | |
} = conf | |
url = | |
"https://compute.googleapis.com/compute/v1/projects/#{project_id}/" <> | |
"zones/#{zone}/instanceGroupManagers/#{instance_group_manager}/resize?key=#{api_key}" | |
headers = [ | |
{"Content-Type", "application/json"}, | |
{"Accept", "application/json"} | |
] | |
Req.post!(url, json: %{size: quantity}, headers: headers) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment