baoshan / fairy

Queue System Treats Tasks Fairly.

Home Page:http://baoshan.github.io/fairy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tasks seem to be executed multiple times

danpres14 opened this issue · comments

I need to build a distributed worker system where a group's tasks are worked in serial fashion. This module looks to be exactly what I need; however, I am running into a problem where it looks like the task is being passed to the worker multiple times. Is this a known issue and if I were to spend the time to code an example, is this code active so that the issue can be fixed quickly?

Thanks,
-Dan

Could you reproduce that? I'm interested.

The module has been deployed with several projects and behaves good so far.

I see there's RedisMsgQueue, but still wish you could reproduce the problem anyway.

Hi, I ran into the same issue. I bet you were calling register multiple times on the same queue. What happens each time you call connect is you get a new instance of fairy so it basically acts like a singleton if you just do it the once at the top of your file. Perhaps this is not the best behavior as it caught out both of us but if you change your code to something like this it should fix the problem.

while worker_count-- > 0
    workerQueueRef = require('fairy').connect().queue(key)
    workerQueueRef.regist (stuff, callback)->

Hi, thanks for pointing out the trap! For now, reuse the fairy object is safe, but not the queue object:

fairy = require('fairy').connect()
while worker_count-- > 0
  fairy.queue(key).regist (stuff, callback) ->

I'll leave the issue open until our developing experience be improved.