Wiki.EventStreams (wiki_elixir v0.2.5) View Source

This module reads from an infinite stream of server-sent events annotating actions such as editing or patrolling, as they happen on Wikimedia projects.

For more about the public wiki streams and their format, see EventStreams on Wikitech

Examples

Start reading the page creation feed, and expose as a GenStage.stream:

Wiki.EventStreams.start_link(streams: "page-create")
Wiki.EventStreams.stream()
|> Stream.take(6)
|> Enum.to_list
|> IO.inspect

Combine multiple feeds,

Wiki.EventStreams.start_link(streams: ["revision-create", "revision-score"])
Wiki.EventStreams.stream()
|> Stream.take(6)
|> Enum.to_list
|> IO.inspect

TODO

  • Currently only a single supervisor tree is supported, so calling applications can only read from one stream.
  • Track the restart ID, disconnect from the feed at some maximum queue size. Reconnect as demand resumes. Application-lifetime or permanent storage for the restart ID tracking, for consumers that need an at-least-once guarantee.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Start a supervisor tree to receive and relay server-side events.

Capture subscribed events and relay them as a Stream.

Link to this section Types

Specs

option() ::
  {:endpoint, String.t()}
  | {:send_to, GenServer.server()}
  | {:streams, atom() | [atom()]}

Specs

options() :: [option()]

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Specs

start_link(options()) :: GenServer.on_start()

Start a supervisor tree to receive and relay server-side events.

Arguments

  • options - Keyword list,
    • {:endpoint, url} - Override default endpoint.
    • {:send_to, pid | module} - Instead of using the built-in streaming relay, send the events directly to your own process.
    • {:streams, atom | [atom]} - Select which streams to listen to. An updated list can be found here. Required.

Specs

stream(keyword()) :: Enumerable.t()

Capture subscribed events and relay them as a Stream.