Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Created March 29, 2023 11:51
Show Gist options
  • Save sorentwo/a54a1e2b37123fd627cca16f07aed951 to your computer and use it in GitHub Desktop.
Save sorentwo/a54a1e2b37123fd627cca16f07aed951 to your computer and use it in GitHub Desktop.
GCP Instance Group Manager for Oban Auto Scaling
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