Skip to content

Support enqueueing arbitrary (non-existing) job classes? #6

Description

@martikaljuve

This is somewhat related to an issue in the Resque project: https://github.com/defunkt/resque/issues/280
I have a Resque job that is added to a dozen different queues and is then performed under several platforms (Windows, Mac OS and Linux) using JRuby. The job gets dispatched to queues from a Ruby application running under MRI Ruby. The dispatcher should not care what libraries are needed on the worker's side to get the job done - it only needs to know the (class)name of the the job and its arguments.

Dummy classes are one way to solve this, but a more generic way would be nice. I currently use a hacky solution to create a job class dynamically on the dispatcher's side if it does not exist:

require 'resque-meta'

module Resque
    def self.enqueue_with_meta_to(queue, klass, *args)
        if klass.is_a? String
            if Object.const_defined? klass
                klass = Resque.constantize klass
            else
                new_klass = Class.new
                Object.const_set klass, new_klass
                new_klass.extend Resque::Plugins::Meta
                klass = new_klass
            end
        end

        klass.instance_variable_set "@queue", queue
        klass.enqueue *args
    end
end

A better way would be to allow Resque::Plugin::Meta::Metadata.new to accept names of non-existing job classes. In that case, the expire_meta_in could be given as an additional constructor argument (instead of finding it from @job_class.expire_meta_in) and Metadata::save should be modified a bit (right now it does job_class.store_meta(self)), along with Metadata::reload!.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions