To give a bit more detail, I'm building an in-house app kind of like Forge. There's a team who manage a number of contractors who aren't technically minded. The app I'm building steps them through the process of creating client websites, from start to final live deployment.
It encapsulates the creation / management of VCS repositories (http://codebasehq.com), deployments (http://deployhq.com) and AWS hosted CentOS boxes.
The specific example would be, when a "website" entity is created in this app, we need to:
If (1) or (2) fail, obviously (3) won't work because it requires an existing VCS repository...
The solution I ended up going with was to make Task (1) fire an event that could be subscribed to in order to queue Task (2), which would fire an event that could be subscribed to in order to queue Task (3), etc...
Hello, I had similiar situation, I expose my solution, it can be useful to someone:
interface StepJob
{
public function nextStep();
public function notify(); //optionally
}
abstract class InstallationJob extends Job implements ShouldQueue, StepJob
{
protected $plan = [
Job1::class => Job2::class,
JobN::class => JobX::class
]
function nextStep()
{
//dispatch next job based on $this->plan dependences or more complex dependences. call notify() when done.
}
}
Create and Register a EventListener (JobsEventListener.php) for events (JobProcessed,JobFailed,JobProcessing):
public function success(JobProcessed $event)
{
$job = $this->unserializeJob($event);
Log::debug("Job Processed ".get_class($job));
if ($job instanceof StepJob)
{
$job->nextStep();
}
}
success function are listening "JobProcessed" Event.
Another considerations:
Process has a model related. nextStep() method updates model taking care with concurrency(using transaction and lockForUpdate). Model is created before start the process and pas on the job constructor.
Now, I need to define another similar process , and I'm thinking about to implement something like http://thispointer.com/task-grouping-using-composite-design-pattern/.
But I'm trying not to get too complicated.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community