Skip to content

Commit

Permalink
Merge pull request #33 from bbalser/optional_timeout
Browse files Browse the repository at this point in the history
Added optional event processing timeout
  • Loading branch information
jdenen authored Nov 6, 2019
2 parents 8328821 + 1ebdb38 commit 93ebd6b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/brook/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/brook/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 93ebd6b

Please sign in to comment.