Skip to content

Instantly share code, notes, and snippets.

@emerleite
Last active February 2, 2018 10:02
Show Gist options
  • Select an option

  • Save emerleite/ea527c66a95cb65bf92f61fe2dbd4472 to your computer and use it in GitHub Desktop.

Select an option

Save emerleite/ea527c66a95cb65bf92f61fe2dbd4472 to your computer and use it in GitHub Desktop.
defmodule UpaEventSourcing.VideoWatchProgress.EventAggregator do
def start_link(event) do
Task.start_link(fn ->
Upa.VideoWatchProgress.save(event) #Saves to the database
end)
end
end
defmodule UpaEventSourcing.VideoWatchProgress.EventConsumer do
use ConsumerSupervisor
alias UpaEventSourcing.VideoWatchProgress.EventStore
alias UpaEventSourcing.VideoWatchProgress.EventAggregator
def start_link(%{producer: EventStore, processor: EventAggregator}) do
children = [
worker(processor, [], restart: :temporary)
]
ConsumerSupervisor.start_link(children,
strategy: :one_for_one,
subscribe_to: [{
producer,
min_demand: 1,
max_demand: 192,
}])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment