Skip to content

Commit

Permalink
Embed README as primary module documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sorentwo committed Nov 6, 2023
1 parent 98d2046 commit abef32e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# Oban.Notifiers.Phoenix

> An [Oban.Notifier][no] that uses [Phoenix.PubSub][pp] for notifications.
<!-- MDOC -->

An [Oban.Notifier][no] that uses [Phoenix.PubSub][pp] for notifications.

The `Phoenix` notifier allows Oban to share a Phoenix application's `PubSub` for notifications. In
addition to centralizing PubSub communications, it opens up the possible transports to all PubSub
adapters.

Most importantly, as Oban already provides `Postgres` and `PG` notifiers, this package enables
Redis notifications via the [Phoenix.PubSub.Redis][pr] adapter.

[no]: https://hexdocs.pm/oban/Oban.Notifier.html
[pp]: https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html
[pr]: https://hex.pm/packages/phoenix_pubsub_redis

## Usage

Include `:oban_notifiers_phoenix` in your Phoenix application's deps:
This package currently requires features only available in Oban `main`. Until Oban v2.17 is
published, you can use this package via GitHub:

```elixir
defp deps do
[
{:oban_notifiers_phoenix, "~> 0.1"},
{:oban, "~> 2.16", github: "sorentwo/oban"},
{:oban_notifiers_phoenix, "~> 0.1", github: "sorentwo/oban_notifiers_phoenix"},
...
]
end
Expand All @@ -36,6 +48,8 @@ config :my_app, Oban,
...
```

<!-- MDOC -->

## Contributing

Run `mix test.ci` locally to ensure changes will pass in CI. That alias executes the following
Expand Down
48 changes: 8 additions & 40 deletions lib/oban/notifiers/phoenix.ex
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
defmodule Oban.Notifiers.Phoenix do
@moduledoc """
An `Oban.Notifier` that uses `Phoenix.PubSub` for notifications.
@external_resource readme = Path.join([__DIR__, "../../../README.md"])

The `Phoenix` notifier allows Oban to share a Phoenix application's `PubSub` for notifications.
In addition to centralizing PubSub communications, it opens up the possible transports to all
PubSub adapters. Most importantly, it enables Redis notifications via the
[Phoenix.PubSub.Redis][pr] adapter
[pr]: https://hex.pm/packages/phoenix_pubsub_redis
## Usage
Include `:oban_notifiers_phoenix` in your application's deps:
```elixir
defp deps do
[
{:oban_notifiers_phoenix, "~> 0.1"},
...
]
end
```
Make note of your application's `Phoenix.PubSub` instance name from the primary supervision tree:
```elixir
def start(_type, _args) do
children = [
{Phoenix.PubSub, name: MyApp.PubSub},
...
```
Finally, configure Oban to use `Oban.Notifiers.Phoenix` as the notifier with the `PubSub`
intance name as the `:pubusb` option:
```elixir
config :my_app, Oban,
notifier: {Oban.Notifiers.Phoenix, pubsub: MyApp.PubSub},
...
```
"""
@moduledoc readme
|> File.read!()
|> String.split("<!-- MDOC -->")
|> Enum.fetch!(1)

@behaviour Oban.Notifier

Expand All @@ -51,6 +16,9 @@ defmodule Oban.Notifiers.Phoenix do
@enforce_keys [:conf, :pubsub]
defstruct @enforce_keys

@doc false
def child_spec(opts), do: super(opts)

@impl Notifier
def start_link(opts) do
{name, opts} = Keyword.pop(opts, :name, __MODULE__)
Expand Down

0 comments on commit abef32e

Please sign in to comment.