Pollin

Simple queue implementation for webhooks and event sources. (Pollin package designed for only callbacks and event sourcing for elixir/erlang applications.)

Motivation

Webhook definition from wikipedia: “Webhooks are “user-defined HTTP callbacks”. They are usually triggered by some event, such as pushing code to a repository or a comment being posted to a blog. When that event occurs, the source site makes an HTTP request to the URI configured for the webhook.”

And a little event sourcing (https://ookami86.github.io/event-sourcing-in-practice/)

Installation

If the package can be installed as:

  1. Add pollin to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:pollin, "~> 0.1.0"}]
end
```
  1. Ensure pollin is started before your application:
```elixir
def application do
  [applications: [:pollin]]
end
```

Usage

Endpoint Resources

# Add alias to your module (optional)
alias Pollin.Backend.Memory.EndpointWorker
alias Pollin.Resource.Endpoint
id = "some_id_for_endpoint"
endpoint = %Endpoint{id: id, secret: "some secret", ttl: 900_000, created_at: :os.system_time}
EndpointWorker.create(endpoint)
id
|> EndpointWorker.find
|> Map.put(:secret, "new secret")
|> EndpointWorker.update
EndpointWorker.delete(id)
EndpointWorker.index
endpoint = EndpointWorker.find(id)

Callbacks Resources(WebHooks / Event Sources)

CallbackWorker.push(id, %Pollin.Resource.Callback{})
callback = CallbackWorker.pop(id)
callback = CallbackWorker.pop(id, key)
callbacks = CallbackWorker.pop(id, opts)
callbacks = CallbackWorker.pop(id, opts)
callback = CallbackWorker.fetch(id)
callback = CallbackWorker.fetch(id, key)
callbacks = CallbackWorker.fetch(id, opts)
callbacks = CallbackWorker.fetch(id, opts)
callbacks = CallbackWorker.fetch(id, opts)
callbacks = CallbackWorker.fetch(id, opts)
count = CallbackWorker.count(id)
count = CallbackWorker.count(id, %{status: "unprocessed"})
callbacks = CallbackWorker.count(id)
CallbackWorker.reset(id)
CallbackWorker.delete(id, key)
CallbackWorker.update_status(id, key, status)

Backends

You can implement your own backend using Pollin.CallbackInterface behaviour.

Contribution

Issues, Bugs, Documentation, Enhancements

  1. Fork the project

  2. Make your improvements and write your tests.

  3. Make a pull request.

Todo

License

MIT