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

jc.getWork always returned: [] #234

Open
tilumi opened this issue May 21, 2017 · 5 comments
Open

jc.getWork always returned: [] #234

tilumi opened this issue May 21, 2017 · 5 comments
Labels

Comments

@tilumi
Copy link

tilumi commented May 21, 2017

I have following small sample for testing jc.getWork.It is wired that I always get empty result from getWork. I wonder is there any problem in this sample?

let jobQueue = new JobCollection('jobQueue');
jobQueue.setLogStream(process.stdout);
if (Meteor.isServer) {
  jobQueue.allow({
    admin: true
  });
}
let jobTypes = {
  convertAndInsert: 'convertAndInsert'
};

if (Meteor.isServer) {
  var worker = function (job, cb) {
    job.done();
    return cb();
  };
  new Job(jobQueue, jobTypes.convertAndInsert, {
    file: "XDDD"
  }).delay(0).save();
  console.log(jobQueue.getWork(jobTypes.convertAndInsert));

}

@tilumi tilumi closed this as completed May 21, 2017
@tilumi
Copy link
Author

tilumi commented May 21, 2017

I found I missed jobQueue.startJobServer();, so close the issue.

@tilumi tilumi reopened this May 21, 2017
@tilumi tilumi closed this as completed May 21, 2017
@vsivsi
Copy link
Owner

vsivsi commented May 21, 2017

@tilumi Glad to figured it out.

You may already know this, but jc.getWork() is a pretty low level function. You should check out jc.processJobs() first to see if it satisfies your requirements. jc.processJobs() is built on top of jc.getWork().

@tilumi tilumi reopened this May 21, 2017
@tilumi
Copy link
Author

tilumi commented May 21, 2017

Yeah, at first I use jc.processJobs() and cannot get jobs to run, so I create this simplest program to debug.
I think throwing an error indicating this problem when calling jc.processJobs() or jc.getWork() is much better for debugging.

@vsivsi
Copy link
Owner

vsivsi commented May 21, 2017

Where would the throw happen? It's not a fatal error, and there's nothing to be done to handle it. There simply isn't any work available before the server is started.

The current behavior is by design, allowing a server to be gracefully shutdown and restarted (e.g. to perform maintenance) without all of the (potentially hundreds of) workers also needing to be restarted.

@tilumi
Copy link
Author

tilumi commented May 21, 2017

OK, throwing exceptions may be inappropriate, but I think a mechanism to acknowledge caller that the server is not started is better, since I stuck for hours to figure out why the work is not got.

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

No branches or pull requests

2 participants