{"action":"created","issue":{"url":"https://api.github.com/repos/juriansluiman/SlmQueue/issues/140","labels_url":"https://api.github.com/repos/juriansluiman/SlmQueue/issues/140/labels{/name}","comments_url":"https://api.github.com/repos/juriansluiman/SlmQueue/issues/140/comments","events_url":"https://api.github.com/repos/juriansluiman/SlmQueue/issues/140/events","html_url":"https://github.com/juriansluiman/SlmQueue/pull/140","id":46568638,"number":140,"title":"[WIP] Feature/job chaining","user":{"login":"basz","id":143068,"avatar_url":"https://avatars.githubusercontent.com/u/143068?v=3","gravatar_id":"","url":"https://api.github.com/users/basz","html_url":"https://github.com/basz","followers_url":"https://api.github.com/users/basz/followers","following_url":"https://api.github.com/users/basz/following{/other_user}","gists_url":"https://api.github.com/users/basz/gists{/gist_id}","starred_url":"https://api.github.com/users/basz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basz/subscriptions","organizations_url":"https://api.github.com/users/basz/orgs","repos_url":"https://api.github.com/users/basz/repos","events_url":"https://api.github.com/users/basz/events{/privacy}","received_events_url":"https://api.github.com/users/basz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2014-10-22T22:31:04Z","updated_at":"2015-02-12T14:20:42Z","closed_at":"2015-02-12T14:20:42Z","pull_request":{"url":"https://api.github.com/repos/juriansluiman/SlmQueue/pulls/140","html_url":"https://github.com/juriansluiman/SlmQueue/pull/140","diff_url":"https://github.com/juriansluiman/SlmQueue/pull/140.diff","patch_url":"https://github.com/juriansluiman/SlmQueue/pull/140.patch"},"body":"Sometimes it is important that one job is executed after an other job has completed. This can be hard to guarantee when more then one worker is handling a queue. This POC PR introduces a simple way to ensure such a requirement.\r\n\r\n```\r\nAbstractJob::chainJob($job);\r\n```\r\nI call this for now a 'chain'. Hence chainJob. Perhaps appendJob would be better.\r\n```\r\n$job = $jobPluginManager->get('MyLongRunningJob');\r\n$chainedJob = $jobPluginManager->get('DoSomethingWithResultJob');\r\n$job->chainJob($job);\r\n$queue->push($job);\r\n```\r\nThese jobs are then added to an array stored as private metadata on the job itself. And thus they become part of the payload.\r\n\r\nUpon job completion any jobs stored in the chain are added to the queue in the same order as they were added (array_shift operation).\r\n\r\nWhy wouldn't I just add DoSomethingWithResultJob from within the MyLongRunningJob you say? Well that requires me to add any content for the DoSomethingWithResultJob to the MyLongRunningJob. But  perhaps more importantly a hardcoded dependency now exists between two (and possibly more) functionally unrelated jobs.\r\n\r\nfurther ideas;\r\n- specify an options indicating when the chained job should be added (when JOB_STATUS_SUCCESS,  JOB_STATUS_FAILURE, or BOTH)\r\n- specify the queueName to add chained jobs (processing and then emailing might be handled by different queues)\r\n- adding chained jobs should probably be handled by a strategy other then the ProcessQueueStrategy\r\n\r\ncomplications;\r\n- A job might fail. Especially with an exception. I havent given much thought too buried jobs. For now I just ignore those. If you successfully recover a job any chained ones will be added upon completion.\r\n\r\nCurious to your thoughts..."},"comment":{"url":"https://api.github.com/repos/juriansluiman/SlmQueue/issues/comments/74077686","html_url":"https://github.com/juriansluiman/SlmQueue/pull/140#issuecomment-74077686","issue_url":"https://api.github.com/repos/juriansluiman/SlmQueue/issues/140","id":74077686,"user":{"login":"basz","id":143068,"avatar_url":"https://avatars.githubusercontent.com/u/143068?v=3","gravatar_id":"","url":"https://api.github.com/users/basz","html_url":"https://github.com/basz","followers_url":"https://api.github.com/users/basz/followers","following_url":"https://api.github.com/users/basz/following{/other_user}","gists_url":"https://api.github.com/users/basz/gists{/gist_id}","starred_url":"https://api.github.com/users/basz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basz/subscriptions","organizations_url":"https://api.github.com/users/basz/orgs","repos_url":"https://api.github.com/users/basz/repos","events_url":"https://api.github.com/users/basz/events{/privacy}","received_events_url":"https://api.github.com/users/basz/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T14:20:42Z","updated_at":"2015-02-12T14:20:42Z","body":"Well, since i needed something i have made it into a module... http://github.com/bushbaby/BsbPostponableJobStrategy"}}