Simple Active Job worker for PostgreSQL using LISTEN/NOTIFY and SKIP LOCKED.
Supports most Active Job features like multiple queues, priorities and wait times.
- PostgreSQL >= 9.5 to use SKIP LOCKED
- Ruby >= 2.3
- Rails >= 5.1
Add this line to your application's Gemfile:
gem 'pg_jobs'
And then execute:
bundle
Then copy the migrations and migrate your database:
bin/rails pg_jobs_engine:install:migrations
bin/rails db:migrate
To configure the Active Job adapter add this to your environment configuration (config/environments/production.rb):
config.active_job.queue_adapter = :pg_jobs
If you want to run all your jobs in one queue, we recommend to configure
ActionMailer to use the default
queue:
config.action_mailer.deliver_later_queue_name = 'default'
You can set the logger for pg_jobs with PgJobs.logger=
:
PgJobs.logger = Logger.new(STDOUT)
PgJobs.logger.level = :debug
It will use ActiveJob::Base.logger
by default.
Note: This does not change the logging behaviour of your jobs, only the log statements of pg_jobs itself.
Just schedule your work with Active Job, then run one or multiple workers for the default queue with
bin/rails runner PgJobs.work
or for other queues with
bin/rails runner "PgJobs.work(:my_queue)"
For more documentation about Active Job and how to use different queues, scheduled jobs, priorities and error handling, see the Active Job Rails Guide.
Use Github issues and pull requests.
The gem is available as open source under the terms of the MIT License.