Coder Social home page Coder Social logo

ceslami / delayed_job_class_name_plugin Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 10 KB

Delayed::Job plugin to record the class name of the enqueued payload object. Great for building an admin dashboard! ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ”ฌ

License: MIT License

Ruby 98.65% Shell 1.35%
ruby delayed-job delayed-jobs plugin rails

delayed_job_class_name_plugin's Introduction

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.

delayed_job_class_name_plugin's People

Contributors

ceslami avatar effron avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

effron

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.