Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martikaljuve opened this issue Jun 29, 2011 · 0 comments
Open

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

martikaljuve opened this issue Jun 29, 2011 · 0 comments

Comments

@martikaljuve
Copy link

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!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant