···78- Support for different subscriptions other than
9 `com.atproto.sync.subscribeRepo'
10-- Support for multiple instances at once, each with unique consumers (for
11- listening to multiple subscriptions at once)
12- Tests
0
···78- Support for different subscriptions other than
9 `com.atproto.sync.subscribeRepo'
0010- Tests
11+- Documentation
+26
examples/basic_consumer.ex
···00000000000000000000000000
···1+defmodule BasicConsumer do
2+ @behaviour Drinkup.Consumer
3+4+ def handle_event(%Drinkup.Event.Commit{} = event) do
5+ IO.inspect(event, label: "Got commit event")
6+ end
7+8+ def handle_event(_), do: :noop
9+end
10+11+defmodule ExampleSupervisor do
12+ use Supervisor
13+14+ def start_link(arg \\ []) do
15+ Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
16+ end
17+18+ @impl true
19+ def init(_) do
20+ children = [
21+ {Drinkup, %{consumer: BasicConsumer}}
22+ ]
23+24+ Supervisor.init(children, strategy: :one_for_one)
25+ end
26+end
+35
examples/multiple_consumers.ex
···00000000000000000000000000000000000
···1+defmodule PostDeleteConsumer do
2+ use Drinkup.RecordConsumer, collections: ["app.bsky.feed.post"]
3+4+ def handle_delete(record) do
5+ IO.inspect(record, label: "update")
6+ end
7+end
8+9+defmodule IdentityConsumer do
10+ @behaviour Drinkup.Consumer
11+12+ def handle_event(%Drinkup.Event.Identity{} = event) do
13+ IO.inspect(event, label: "identity event")
14+ end
15+16+ def handle_event(_), do: :noop
17+end
18+19+defmodule ExampleSupervisor do
20+ use Supervisor
21+22+ def start_link(arg \\ []) do
23+ Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
24+ end
25+26+ @impl true
27+ def init(_) do
28+ children = [
29+ {Drinkup, %{consumer: PostDeleteConsumer}},
30+ {Drinkup, %{consumer: IdentityConsumer, name: :identities}}
31+ ]
32+33+ Supervisor.init(children, strategy: :one_for_one)
34+ end
35+end
+2-2
examples/record_consumer.ex
···17defmodule ExampleSupervisor do
18 use Supervisor
1920- def start_link(args \\ []) do
21 Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
22 end
2324 @impl true
25 def init(_) do
26 children = [
27- {Drinkup, %{module: ExampleRecordConsumer}}
28 ]
2930 Supervisor.init(children, strategy: :one_for_one)
···17defmodule ExampleSupervisor do
18 use Supervisor
1920+ def start_link(arg \\ []) do
21 Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
22 end
2324 @impl true
25 def init(_) do
26 children = [
27+ {Drinkup, %{consumer: ExampleRecordConsumer}}
28 ]
2930 Supervisor.init(children, strategy: :one_for_one)
+8
lib/application.ex
···00000000
···1+defmodule Drinkup.Application do
2+ use Application
3+4+ def start(_type, _args) do
5+ children = [{Registry, keys: :unique, name: Drinkup.Registry}]
6+ Supervisor.start_link(children, strategy: :one_for_one)
7+ end
8+end
+23-14
lib/drinkup.ex
···1defmodule Drinkup do
2 use Supervisor
034- @type options() :: %{
5- required(:consumer) => module(),
6- optional(:host) => String.t(),
7- optional(:cursor) => pos_integer()
8- }
00910- @spec start_link(options()) :: Supervisor.on_start()
11- def start_link(options) do
12- Supervisor.start_link(__MODULE__, options, name: __MODULE__)
013 end
1415- def init(options) do
16- children = [
17- {Task.Supervisor, name: Drinkup.TaskSupervisor},
18- {Drinkup.Socket, options}
19- ]
2021- Supervisor.init(children, strategy: :one_for_one)
0000000022 end
23end
···4 """
56 require Logger
7+ alias Drinkup.{Event, Options}
89 @behaviour :gen_statem
010 @timeout :timer.seconds(5)
11 # TODO: `flow` determines messages in buffer. Determine ideal value?
12 @flow 10
···29 }
30 end
3132+ def start_link(%Options{} = options, statem_opts) do
0033 :gen_statem.start_link(__MODULE__, options, statem_opts)
34 end
35···118 Logger.warning("Received unrecognised event from firehose: #{inspect({type, payload})}")
119120 message ->
121+ Event.dispatch(message, options)
122 end
123124 {:keep_state, data}
+2-1
mix.exs
···14 # Run "mix help compile.app" to learn about applications.
15 def application do
16 [
17- extra_applications: [:logger]
018 ]
19 end
20
···14 # Run "mix help compile.app" to learn about applications.
15 def application do
16 [
17+ extra_applications: [:logger],
18+ mod: {Drinkup.Application, []}
19 ]
20 end
21