Skip to content

Unhandled error when using queue.getJob(job_id) on job that doesn't exist #35

Closed

Description

@avermeil

If I call queue.getJob(id) on an id that doesn't exist, the function fails without calling the failure callback.

Below, the call to hget returns null, so in fromData(), instantiating the job fails because data.data doesn't exist. By then we're already on the success-side of the callback, so there's no way to recover, as far as I know.

Is there something I'm missing?

Job.fromId = function (queue, jobId, cb) {
  queue.client.hget(queue.toKey('jobs'), jobId, function (err, data) {
    /* istanbul ignore if */
    if (err) return cb(err);
    return cb(null, Job.fromData(queue, jobId, data));
  });
};

Job.fromData = function (queue, jobId, data) {
  // no need for try-catch here since we made the JSON ourselves in job#toData
  data = JSON.parse(data);
  var job = new Job(queue, jobId, data.data, data.options);
  job.status = data.status;
  return job;
};

Activity

  1. LewisJEllis commented on Jan 19, 2016

    @LewisJEllis
    Member

    Ah, I had assumed that a missing key would return an error in the hget callback, but apparently that's not the case.

    This is definitely a bug; thanks for the catch. I'll put in a fix with the upcoming release.

  2. avermeil commented on Jan 19, 2016

    @avermeil
    Author

    Great! Is there a rough timeline for the upcoming release?

  3. added this to the 1.0.0 milestone on Jul 20, 2017
  4. skeggse commented on Jul 20, 2017

    @skeggse
    Member

    The rough timeline is now #64.

  5. skeggse commented on Aug 9, 2017

    @skeggse
    Member

    Oops, #48 is a duplicate of this. Also, this is fixed in 1.0.0 (f2cfb01).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions