{"action":"created","issue":{"url":"https://api.github.com/repos/silverstripe-australia/silverstripe-queuedjobs/issues/26","labels_url":"https://api.github.com/repos/silverstripe-australia/silverstripe-queuedjobs/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/silverstripe-australia/silverstripe-queuedjobs/issues/26/comments","events_url":"https://api.github.com/repos/silverstripe-australia/silverstripe-queuedjobs/issues/26/events","html_url":"https://github.com/silverstripe-australia/silverstripe-queuedjobs/issues/26","id":48572577,"number":26,"title":"Ensure multiple queue processors don't run duplicate jobs","user":{"login":"sminnee","id":59968,"avatar_url":"https://avatars.githubusercontent.com/u/59968?v=3","gravatar_id":"","url":"https://api.github.com/users/sminnee","html_url":"https://github.com/sminnee","followers_url":"https://api.github.com/users/sminnee/followers","following_url":"https://api.github.com/users/sminnee/following{/other_user}","gists_url":"https://api.github.com/users/sminnee/gists{/gist_id}","starred_url":"https://api.github.com/users/sminnee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sminnee/subscriptions","organizations_url":"https://api.github.com/users/sminnee/orgs","repos_url":"https://api.github.com/users/sminnee/repos","events_url":"https://api.github.com/users/sminnee/events{/privacy}","received_events_url":"https://api.github.com/users/sminnee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-11-12T22:36:14Z","updated_at":"2015-03-19T19:31:12Z","closed_at":null,"body":"Right now queuedjobs seems to rely on only 1 copy of the worker process running. If you have multiple workers running—e.g. for scaling, or because you have more than 1 server and it's easier to configure them the same—race conditions can lead to a single job being executed more than once.\r\n\r\nIt would be better if the queuedjobs module guarded against this. Presumably this would involve updating the status from the non-running state to the running state in a single command:\r\n\r\n    UPDATE \"QueuedJobDescriptor\" SET \"JobStatus\" = 'Running'\r\n    WHERE \"JobStatus\" IN ('New', 'Waiting') AND \"ID\" = $jobID\r\n\r\nIf this command didn't affect any rows, then we know someone else as handled the job and we can exit without running the job.\r\n\r\nI guess this goes in here? https://github.com/silverstripe-australia/silverstripe-queuedjobs/blob/master/code/services/QueuedJobService.php#L395"},"comment":{"url":"https://api.github.com/repos/silverstripe-australia/silverstripe-queuedjobs/issues/comments/83732081","html_url":"https://github.com/silverstripe-australia/silverstripe-queuedjobs/issues/26#issuecomment-83732081","issue_url":"https://api.github.com/repos/silverstripe-australia/silverstripe-queuedjobs/issues/26","id":83732081,"user":{"login":"silverstripe-elliot","id":5863816,"avatar_url":"https://avatars.githubusercontent.com/u/5863816?v=3","gravatar_id":"","url":"https://api.github.com/users/silverstripe-elliot","html_url":"https://github.com/silverstripe-elliot","followers_url":"https://api.github.com/users/silverstripe-elliot/followers","following_url":"https://api.github.com/users/silverstripe-elliot/following{/other_user}","gists_url":"https://api.github.com/users/silverstripe-elliot/gists{/gist_id}","starred_url":"https://api.github.com/users/silverstripe-elliot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silverstripe-elliot/subscriptions","organizations_url":"https://api.github.com/users/silverstripe-elliot/orgs","repos_url":"https://api.github.com/users/silverstripe-elliot/repos","events_url":"https://api.github.com/users/silverstripe-elliot/events{/privacy}","received_events_url":"https://api.github.com/users/silverstripe-elliot/received_events","type":"User","site_admin":false},"created_at":"2015-03-19T19:31:12Z","updated_at":"2015-03-19T19:31:12Z","body":"@stojg could you use database locks? Something like this: https://github.com/silverstripe-elliot/silverstripe-queuedjobs/commit/f52fdbe6fd9e85fe6378cba9246216f6f1865189"}}