msavin / SteveJobs

A simple jobs queue that just works (for Meteor.js)
Other
207 stars 35 forks source link

Jobs: Unable to execute job - queue is busy, randomly appearing. #93

Closed Gorbus closed 3 years ago

Gorbus commented 3 years ago

Hi @msavin,

We are using Jobs in production and generally everything works very fine. However once in a while we get the following message:

image

And while it doesn't seem to block the other jobs this one can get stuck and affect our user experience. The appearance of the message seems very random to us. Therefore I'd like to know:

Thanks in advance for your help. The registered job is the following:

Jobs.register({
  submitTeamAnswerJob: function (
    challengeId,
    isAdmin,
    teamId,
    sessionId,
    activityId
  ) {
    const activity = Activities.findOne({ _id: activityId });

    try {
      if (activity) {
        const { liveSessions } = activity;
        const session = liveSessions.find(({ _id }) => _id === sessionId);
        const { teams } = session;
        const team = teams.find(({ _id }) => _id === teamId);
        const { name } = team;
        submitTeamAnswer({
          challengeId,
          isAdmin,
          teamId,
          sessionId,
          teamName: name,
        });
      }
    } catch (e) {
      console.log(e);
    }

    this.success();
  },
});

I just added the try catch by security (could it help) ? But the error message happened before the try catch was set up. We didn't get any error regarding the submitTeamAnswer function when it was triggered.

Gorbus commented 3 years ago

It seems it may be appearing sometimes when we're trying to force the execution of the job before it was triggered using Jobs.execute.

I just saw Jobs.execute can have a "force" boolean passed to it, what's its use exactly, is it any good to use in production ? what are the risks ?

Edit: Somehow Forcing the jobs Executions : Jobs.execute(jobId, true) seems to solve our issue as it forces the trigger of the function but I really am not sure about using it and possible consequences.

msavin commented 3 years ago

Hey @Gorbus - sorry for the delay - but yes passing in the force function is the right thing to do. So long as you don't try to simultaneously force 1000 jobs to execute at the same time, should be ok :)

Please let me know if you have any other issues