From e3f8052f5a76ad827a96f7dbc788bb2b45886a17 Mon Sep 17 00:00:00 2001 From: Brian Balser Date: Wed, 6 Nov 2019 14:49:12 -0500 Subject: [PATCH 1/2] Added optional event processing timeout --- lib/brook/config.ex | 11 +++++++++-- lib/brook/event.ex | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/brook/config.ex b/lib/brook/config.ex index 13ab062..b30c7f2 100644 --- a/lib/brook/config.ex +++ b/lib/brook/config.ex @@ -14,7 +14,8 @@ defmodule Brook.Config do event_handlers: nil, storage: nil, dispatcher: nil, - registry: nil + registry: nil, + event_processing_timeout: nil @doc """ Take a keyword list and extracts values necessary to configure a Brook @@ -31,7 +32,8 @@ defmodule Brook.Config do event_handlers: Keyword.fetch!(opts, :handlers), storage: Keyword.get(opts, :storage, @default_storage) |> Enum.into(%{}), dispatcher: Keyword.get(opts, :dispatcher, @default_dispatcher), - registry: registry(instance) + registry: registry(instance), + event_processing_timeout: Keyword.get(opts, :event_processing_timeout, 5_000) } end @@ -63,6 +65,10 @@ defmodule Brook.Config do get_value(instance, :dispatcher) end + def event_processing_timeout(instance) do + get_value(instance, :event_processing_timeout) + end + def start_link(args) do GenServer.start_link(__MODULE__, args) end @@ -74,6 +80,7 @@ defmodule Brook.Config do Registry.put_meta(config.registry, :event_handlers, config.event_handlers) Registry.put_meta(config.registry, :storage, config.storage) Registry.put_meta(config.registry, :dispatcher, config.dispatcher) + Registry.put_meta(config.registry, :event_processing_timeout, config.event_processing_timeout) {:ok, [], {:continue, :done}} end diff --git a/lib/brook/event.ex b/lib/brook/event.ex index 80c2d3e..139811b 100644 --- a/lib/brook/event.ex +++ b/lib/brook/event.ex @@ -85,7 +85,8 @@ defmodule Brook.Event do @spec process(Brook.instance(), Brook.Event.t() | term()) :: :ok | {:error, Brook.reason()} def process(instance, event) do registry = Brook.Config.registry(instance) - GenServer.call({:via, Registry, {registry, Brook.Server}}, {:process, event}) + timeout = Brook.Config.event_processing_timeout(instance) + GenServer.call({:via, Registry, {registry, Brook.Server}}, {:process, event}, timeout) end defp now(), do: DateTime.utc_now() |> DateTime.to_unix(:millisecond) From 1ebdb38baf15e0df8def3563b370ed0209818c84 Mon Sep 17 00:00:00 2001 From: Johnson Denen Date: Wed, 6 Nov 2019 15:37:22 -0500 Subject: [PATCH 2/2] Bump to v0.4.9 --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 72e07e2..69e5916 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Brook.MixProject do def project do [ app: :brook, - version: "0.4.8", + version: "0.4.9", elixir: "~> 1.8", description: description(), package: package(),