{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/kue/issues/918","repository_url":"https://api.github.com/repos/Automattic/kue","labels_url":"https://api.github.com/repos/Automattic/kue/issues/918/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/kue/issues/918/comments","events_url":"https://api.github.com/repos/Automattic/kue/issues/918/events","html_url":"https://github.com/Automattic/kue/issues/918","id":165440333,"number":918,"title":"Cluster workers not being able to pick up Jobs / double pick up","user":{"login":"JperF","id":4474118,"avatar_url":"https://avatars.githubusercontent.com/u/4474118?v=3","gravatar_id":"","url":"https://api.github.com/users/JperF","html_url":"https://github.com/JperF","followers_url":"https://api.github.com/users/JperF/followers","following_url":"https://api.github.com/users/JperF/following{/other_user}","gists_url":"https://api.github.com/users/JperF/gists{/gist_id}","starred_url":"https://api.github.com/users/JperF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JperF/subscriptions","organizations_url":"https://api.github.com/users/JperF/orgs","repos_url":"https://api.github.com/users/JperF/repos","events_url":"https://api.github.com/users/JperF/events{/privacy}","received_events_url":"https://api.github.com/users/JperF/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-07-13T22:57:23Z","updated_at":"2016-07-14T16:49:19Z","closed_at":null,"body":"The following program will create two `cluster` workers, then one job task. The job task will be marked as failed immediately. Every second the job is marked back as `inactive` which should be picked up again by a single worker. However occasionally more than one worker is picking up the job cause it to be executed twice.  \r\n\r\nIs there something wrong with my logic or is this an issue with the cluster implementation in `kue`? \r\n\r\n\r\n````javascript\r\nvar kue = require('kue');\r\nvar jobs = kue.createQueue();\r\nvar cluster = require('cluster');\r\n\r\nif(cluster.isMaster){\r\n    cluster.fork();\r\n    cluster.fork();\r\n    jobs.create('test').save();\r\n\r\n    setInterval(function () {\r\n        kue.Job.rangeByState( 'failed', 0, -1, 'asc', function( err, jobs ) {\r\n            if(err){\r\n                console.log(err);\r\n            }\r\n            else{\r\n                jobs.forEach( function ( job ) {\r\n                    job.state('inactive').save();\r\n                });\r\n            }\r\n        });\r\n    }, 1000);\r\n}\r\n\r\nif(cluster.isWorker){\r\n    jobs.process('test', function ( job, done ) {\r\n        console.log('worker' , cluster.worker.id + ' has control of: ' + job.id + ' | ' +  new Date());\r\n        done('failed');\r\n    });\r\n}\r\nelse{\r\n    jobs.on('job failed', function ( errorMessage ) {\r\n        console.log('Job failed');\r\n    })\r\n}\r\n````\r\n\r\nWhen running the following program the jobs are eventually are not picked up at all.\r\n\r\n#### Note: The done call is never called in this example which causes the state of the jobs to be changed from `active` to `inactive`. Instead of `failed` to `inactive` like the previous example.\r\n\r\n````javascript\r\nvar kue = require('kue');\r\nvar jobs = kue.createQueue();\r\nvar cluster = require('cluster');\r\n\r\nif(cluster.isMaster){\r\n    cluster.fork();\r\n    cluster.fork();\r\n    jobs.create('test').save();\r\n\r\n    setInterval(function () {\r\n        kue.Job.rangeByState( 'active', 0, -1, 'asc', function( err, jobs ) {\r\n            if(err){\r\n                console.log(err);\r\n            }\r\n            else{\r\n                jobs.forEach( function ( job ) {\r\n                    job.state('inactive').save();\r\n                });\r\n            }\r\n        });\r\n    }, 1000);\r\n}\r\n\r\nif(cluster.isWorker){\r\n    jobs.process('test', function ( job, done ) {\r\n        console.log('worker' , cluster.worker.id + ' has control of: ' + job.id + ' | ' +  new Date());\r\n    });\r\n}\r\nelse{\r\n    jobs.on('job failed', function ( errorMessage ) {\r\n        console.log('Job failed');\r\n    })\r\n}\r\n````"},"comment":{"url":"https://api.github.com/repos/Automattic/kue/issues/comments/232723815","html_url":"https://github.com/Automattic/kue/issues/918#issuecomment-232723815","issue_url":"https://api.github.com/repos/Automattic/kue/issues/918","id":232723815,"user":{"login":"JperF","id":4474118,"avatar_url":"https://avatars.githubusercontent.com/u/4474118?v=3","gravatar_id":"","url":"https://api.github.com/users/JperF","html_url":"https://github.com/JperF","followers_url":"https://api.github.com/users/JperF/followers","following_url":"https://api.github.com/users/JperF/following{/other_user}","gists_url":"https://api.github.com/users/JperF/gists{/gist_id}","starred_url":"https://api.github.com/users/JperF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JperF/subscriptions","organizations_url":"https://api.github.com/users/JperF/orgs","repos_url":"https://api.github.com/users/JperF/repos","events_url":"https://api.github.com/users/JperF/events{/privacy}","received_events_url":"https://api.github.com/users/JperF/received_events","type":"User","site_admin":false},"created_at":"2016-07-14T16:49:18Z","updated_at":"2016-07-14T16:49:18Z","body":"Same problem is happening as I initially stated:\r\n\r\n>  However occasionally more than one worker is picking up the job cause it to be executed twice.\r\n\r\nNote that only a maximum of 2 workers ever pick up the job regardless of how many there are. "}}
{"actor":{"display_login":"JperF"}}