Commit 522032888bba230afc5a731fd643d742176c6b0b

Stephen Moloney 2016-02-12T21:39:45

add dynamic supervisor for openstack stacks ...

diff --git a/lib/ovh/openstack_api/webstorage/supervisor.ex b/lib/ovh/openstack_api/webstorage/supervisor.ex
new file mode 100644
index 0000000..f3d2dca
--- /dev/null
+++ b/lib/ovh/openstack_api/webstorage/supervisor.ex
@@ -0,0 +1,43 @@
+defmodule ExOvh.Ovh.OpenstackApi.Supervisor do
+  @moduledoc ~s"""
+  Supervisor for the Ovh Openstack Configurations.
+
+  Rather than adding every single instance of an openstack account to the `secret.prod.exs` file, it is
+  probably better to start the openstack workers on demand.
+
+  The openstack workers cache the openstack token and maintain it.
+  """
+  use Supervisor
+  alias ExOvh.Ovh.OpenstackApi.Webstorage.Cache
+
+  #####################
+  #  Public
+  #####################
+
+  @doc ~s"""
+  Starts the OVH Openstack dynamic supervisor.
+  """
+  def start_link({client, config, opts}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+
+    LoggingUtils.log_return("starting dynamic supervisor", :warn)
+
+    {:ok, sup_pid} = Supervisor.start_link(__MODULE__, {client, config, opts}, [name: __MODULE__])
+    |> LoggingUtils.log_return(:warn)
+  end
+
+
+  #####################
+  #  Callbacks
+  #####################
+
+  def init({client, config, opts}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    tree = [
+            {Cache, {Cache, :start_link, [{client, config, opts}]}, :transient, 10_000, :worker, []}
+           ]
+    supervise(tree, strategy: :simple_one_for_one)
+  end
+
+
+end