errorception / redis-lock

Implements a locking primitive using redis. An implementation of the algorithm described at https://redis.io/commands/setnx
211 stars 48 forks source link

TypeError: object is not a function #16

Closed satblip closed 9 years ago

satblip commented 9 years ago

I run a worker that consume a queue.

I works quite well, but sometimes trough me this error, any idea?

TypeError: object is not a function
   node_1  |     at /var/www/node_modules/redis-lock/index.js:43:6

This is the code for the lock part:

lock('workerLock', function (done) {
    return Promise.join(
      dailyWorker()
    ).spread(function (daily, monthly) {
      return saveToDb(daily, monthly);
    })
    .then(function () {
      done(setTimeout(mainWorker, 1000));
    })
    .catch(function (err) {
      logger.error(err.stack, 'error');
    });

  });

Thanks!

rakeshpai commented 9 years ago

@satblip Your code looks right. Could you insert a console.log in your node_modules/redis-lock/index.js before line 43 to check what the value of done is? It should be equal to the function you are passing into the lock function. If it isn't, that's your bug.

It certainly seems from the error message that what's getting passed in isn't a function, but an object of some sort.

satblip commented 9 years ago

Hi,

I've found the issue, it was indeed on my side. I did correct it like this :


lock('workerLock', function (done) {
    return Promise.join(
      dailyWorker()
    ).spread(function (daily, monthly) {
      return saveToDb(daily, monthly);
    })
    .then(function () {
      done();
      setTimeout(mainWorker, 1000));
    })
    .catch(function (err) {
      logger.error(err.stack, 'error');
    });

  });