No commit activity in last 3 years
No release in over 3 years
Delayed::Job plugin to record the class name of the enqueued payload object
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

< 11.0
= 3.3.0

Runtime

>= 4.1.0, ~> 4.1
 Project Readme

Delayed::ClassName Plugin

Delayed Job records a serialized payload object to the delayed_jobs table. If you want to know what kinds of jobs are currently enqueued, you must write complicated and brittle queries that parse the serialized payloads (ie the Delayed::Job#handler column). This gem exists to make queue administration more convenient. ✨

This plugin adds an indexed class_name column to the delayed_jobs table. By default, it contains the stringified class name of the enqeued payload object.

Installation

Add this line to your application's Gemfile:

gem 'delayed_job_class_name_plugin'

And then execute:

$ bundle

Or install it yourself as:

$ gem install delayed_job_class_name_plugin

Run the required database migrations:

$ rails generate delayed_job_class_name_plugin:install
$ rails db:migrate

Usage

In certain cases, you may want to parse the payload object in a custom way to derive its "class name."

For example, ActiveJob in Rails, will always enqueue a JobWrapper as the payload object. This object, predictably, wraps the object that's actually doing work. By default, "JobWrapper" would be the value of Delayed::Job#class_name. You may find this less helpful than having #class_name contain the class of the wrapped object.

Let's see how we can use the #custom_parser configuration to accomplish this:

# config/initializers/delayed_job.rb

Delayed::ClassName.configure do |c|
  c.custom_parser = ->(payload_object) {
    if payload_object.class == ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper
      payload_object.job_data['job_class']
    else
      payload_object.class.name
    end
  }
end

Configuration#custom_parser can take a Proc which receives a single parameter, job, and returns a String that will be written to Delayed::Job#class_name at enqueue-time.

License

The gem is available as open source under the terms of the MIT License.