diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-21 19:14:00 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-21 19:14:00 -0400 |
commit | 7a9741e3f6fd64ae492697560f61cad7ef9e0cb4 (patch) | |
tree | 63a1614529615b806224abf453a9b974aadd7bf7 /lib/polyjuice/client.ex | |
parent | automatically start sync process (diff) |
automatically start/stop sync when logging in/out
Diffstat (limited to 'lib/polyjuice/client.ex')
-rw-r--r-- | lib/polyjuice/client.ex | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/polyjuice/client.ex b/lib/polyjuice/client.ex index 2a15d28..6cf1c84 100644 --- a/lib/polyjuice/client.ex +++ b/lib/polyjuice/client.ex @@ -49,6 +49,7 @@ defmodule Polyjuice.Client do id: integer, storage: Polyjuice.Client.Storage.t(), handler: Polyjuice.Client.Handler.t(), + opts: list, test: boolean } @@ -59,6 +60,7 @@ defmodule Polyjuice.Client do :storage, :handler, sync: true, + opts: [], test: false ] @@ -126,6 +128,7 @@ defmodule Polyjuice.Client do storage: storage, handler: handler, sync: sync, + opts: opts, test: Keyword.get(opts, :test, false) } end @@ -368,6 +371,15 @@ defmodule Polyjuice.Client do ) end + if client.sync do + supervisor_name = process_name(client.id, :supervisor) + + Supervisor.start_child( + supervisor_name, + sync_child_spec(client.base_url, client.id, client.opts) + ) + end + ret end @@ -376,6 +388,10 @@ defmodule Polyjuice.Client do """ @spec log_out(client :: Polyjuice.Client.t()) :: {:ok} | any def log_out(client) do + supervisor_name = process_name(client.id, :supervisor) + Supervisor.terminate_child(supervisor_name, Polyjuice.Client.Sync) + Supervisor.delete_child(supervisor_name, Polyjuice.Client.Sync) + {:ok} = Polyjuice.Client.API.call( client, |