add dynamic supervisor for openstack stacks ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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