Automattic / kue

Kue is a priority job queue backed by redis, built for node.js.
http://automattic.github.io/kue
MIT License
9.45k stars 865 forks source link

Not able to pass classes and objects via job's data #903

Open snig-b opened 8 years ago

snig-b commented 8 years ago

I want to pass an object created before creating the job, and a class to the job's data. That job is generic and would be working on multiple classes depending on properties passed to the job. I do not want to hard code the class names in my job processing. But the job process that I have written, does not receive class and method values, the whole key-value pair is missing from job.data. All other simple key-value pairs are present.

Example:

 const job = this.queue.create(jobType, {
        title: 'Some title for '+ source,
        identifier: userIdentifier,
        source: source,
        graphLoader: this.getGraphLoader(source), // This is a class
        redis: this.redis // This is an object
    }).backoff({delay: graphConstants.graphPopulationRetryDelay,
        type: 'exponential'}).

What my job.data includes:

{ title: 'Some title for abcd',
  identifier: '79398',
  source: 'abcd',
  redis: 
   { options: { host: 'xx.xx.xx.xxx', port: 6379, db: '14', sep: '--' }} }

As is visible, the class key-value pair is missing. And the object's key value pair simply is an object with the object's attribute, not the actual object!

How do I find a solution for this?

runvnc commented 8 years ago

@snig-b kue stores your job data in redis, and redis doesn't know about JavaScript classes. You could do something like this:

job.process(jobType, function(job, done) {
  var processor = self['get'+job.class](job);
  processor.process(done);
});

job.create(jobType, { class: 'GraphLoader', source: source });