Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Last active March 19, 2023 20:54
Show Gist options
  • Save sorentwo/54d99fb2ac05cb63ea1e30aa1935b6fc to your computer and use it in GitHub Desktop.
Save sorentwo/54d99fb2ac05cb63ea1e30aa1935b6fc to your computer and use it in GitHub Desktop.

Revisions

  1. sorentwo revised this gist Mar 19, 2023. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions heroku.ex
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,6 @@ defmodule Oban.Pro.Clouds.Heroku do

    @behaviour Oban.Pro.Cloud

    alias Oban.Pro.Cloud

    @enforce_keys [:app, :auth_token, :dyno]
    defstruct @enforce_keys

    @@ -16,14 +14,13 @@ defmodule Oban.Pro.Clouds.Heroku do
    @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}"
    body = Jason.encode!(%{quantity: quantity})

    headers = [
    {"Content-Type", "application/json"},
    {"Accept", "application/vnd.heroku+json; version=3"},
    {"Authorization", "Bearer #{auth_token}"}
    ]

    Cloud.request(:patch, url, body, headers)
    Req.patch!(url, json: %{quantity: quantity}, headers: headers)
    end
    end
  2. sorentwo created this gist Mar 17, 2023.
    29 changes: 29 additions & 0 deletions heroku.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    defmodule Oban.Pro.Clouds.Heroku do
    @moduledoc false

    @behaviour Oban.Pro.Cloud

    alias 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}"
    body = Jason.encode!(%{quantity: quantity})

    headers = [
    {"Content-Type", "application/json"},
    {"Accept", "application/vnd.heroku+json; version=3"},
    {"Authorization", "Bearer #{auth_token}"}
    ]

    Cloud.request(:patch, url, body, headers)
    end
    end