Last active
February 2, 2018 10:02
-
-
Save emerleite/ea527c66a95cb65bf92f61fe2dbd4472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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