juriansluiman/SlmQueue — pull request #140 by basz (2014-10-22 22:31:04+00:00)
Title: [WIP] Feature/job chaining

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.

```
AbstractJob::chainJob($job);
```
I call this for now a 'chain'. Hence chainJob. Perhaps appendJob would be better.
```
$job = $jobPluginManager->get('MyLongRunningJob');
$chainedJob = $jobPluginManager->get('DoSomethingWithResultJob');
$job->chainJob($job);
$queue->push($job);
```
These jobs are then added to an array stored as private metadata on the job itself. And thus they become part of the payload.

Upon job completion any jobs stored in the chain are added to the queue in the same order as they were added (array_shift operation).

Why wouldn't I just add DoSomethingWithResultJob from with the MyLongRunningJob you say? Well I need to add all content the DoSomethingWithResultJob might need to the MyLongRunningJob and perhaps more important a hardcoded dependency now exists between two functionally unrelated Job.

further ideas;
- specify an options indicating when the chained job should be added (when JOB_STATUS_SUCCESS, JOB_STATUS_FAILURE, or BOTH)
- specify the queueName to add chained jobs (processing and then emailing might be handled by different queues)
- adding chained jobs should probably be handled by a strategy other then the ProcessQueueStrategy

complications;
- 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.

Curious to your thoughts...