ActiveJob::Trackable
include ActiveJob::Trackable
into any jobs you want to track. Tracking jobs will grant you
access into the lifetime of each jobs and give you the ability to throttle and debounce similar jobs.
This is useful for cases where you want to make sure that certain jobs are only done at most once per certain period or when you want to reschedule/reconfigure previously scheduled jobs
Usage
This gem is build with composition over inheritance in mind, and so to benefit from it
you can start by adding include ActiveJob::Trackable
into any jobs you want to track, e.g.
class SampleJob < ApplicationJob
include ActiveJob::Trackable
trackable debounced: true, throttled: 1.day
def perform(one, two, three); end
end
Calling trackable
configures the trackers behavior, which defaulted to doing nothing.
Using this, you can tell the trackers to either :debounced
, :throttled
, or both.
ActiveJob::Trackable::Debounced
and ActiveJob::Trackable::Throttled
is also available as syntactic sugar
Compatibility
For now, this gem only support delayed_job
with activerecord
backend,
but support for other delayed job backend and other queue adapters are desired.
Installation
Add this line to your application's Gemfile:
gem 'activejob-trackable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activejob-trackable
run the generator:
rails generate active_job:trackable
and run the generated migration:
rake db:migrate
Contributing
Any and all kind of help are welcomed! Especially interested in:
- support for other delayed job backend
- support for other queue adapters officially supported by
activejob
itself
feel free to file an issue/PR!
License
The gem is available as open source under the terms of the MIT License.