mbuhot
EctoJob - a transactional job queue built with Ecto, PostgreSQL and GenStage
EctoJob
A transactional job queue built with Ecto, PostgreSQL and GenStage
Available on Hex.pm: ecto_job | Hex
Docs: API Reference — ecto_job v3.1.0
Github: GitHub - mbuhot/ecto_job: Transactional job queue with Ecto, PostgreSQL and GenStage · GitHub
Goals
- Transactional job processing
- Retries
- Scheduled jobs
- Multiple queues
- Low latency concurrent processing
- Avoid frequent database polling
- Library of functions, not a full OTP application
Details
One of the distinguishing features of ecto_job is that the API encourages transactional job processing through Ecto.Multi. Job handlers are passed an Ecto.Multi parameter that must be passed to Repo.transaction to complete the job.
def perform(multi = %Ecto.Multi{}, job = %{}) do
multi
|> do_first_thing(job["customer_id"])
|> do_second_thing(job["product_id"])
|> MyApp.Repo.transaction()
end
Similarly, there are helpers to encourage transactional job creation by adding to an Ecto.Multi
Multi.new()
|> Multi.insert(:add_user, User.insert_changeset(%{name: "Joe", email: "joe@gmail.com"}))
|> JobQueue.enqueue(:email_job, %{"type" => "SendEmail", "address" => "joe@gmail.com", "body" => "Welcome!"})
|> MyApp.Repo.transaction()
Jobs are processed using a GenStage producer and ConsumerSupervisor that will execute jobs concurrently up to a configurable max_demand.
Postgrex.Notifications is used to trigger job processors as soon as the transaction that adds a job is committed.
Job workers can be run on a separate node, without requiring any beam clustering, just PostgreSQL listen/notify.
Job completion is also signalled using listen/notify enabling websocket or chunked HTTP responses (on another node) to be triggered once a job completes.
Similar libraries:
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First Post!
outlog
awesome - look forward to battle testing it.
Most Liked
mbuhot
EctoJobversion 2.0.0 has been published to Hex.pm.EctoJob2.0 depends on Ecto 3.0, but is otherwise backwards compatible with existing code.Other changes in this release:
schema_prefix.:bigserialprimary key instead of relying on theectodefault.Hex Package
Docs
Source
mbuhot
EctoJobversion 2.1.0 has been released.Version 2.1 adds support for requeing jobs, fixes to the job reservation algorithm and dialyzer warnings.
Changelog
Hex Package
Docs
Thank you to everyone that contributed to this version!
I’d also like to invite any users of EctoJob to please raise issues on the GitHub page for any features you’d like to see added or would be willing to work on (admin UI, Telemetry, Pre/Post job hooks, etc..)
mbuhot
EctoJob version 3.1 has been released
Changelog
Hex Package
Docs
Version 3.1.0 adds support for MySQL 8 and storing job params as an Elixir/Erlang term.
You can insert any arbitrary Elixir/Erlang term into the queue:
You should use the option
:params_typewhen defining your queue module:Possible values of the option are:
:map(default) and:binary(for storing Elixir/Erlang terms).You should use the same option when setting up the migration:
We are looking forward to releasing a new major version soon with support for completed job retention and job idempotency. Stay tuned
Last Post!
towhans
Adding this to Repo config helped. The param is documented here: Postgrex.Notifications — Postgrex v0.22.2
I believe the issue is somehow network related. Not a problem in code.