'Cake PHP run multiple Console/cake shell commands in different processes
I've written a Console/cake shell for my Cake PHP 2 project. My shell is called a Queue Manager, and it contains two tasks, a ProcessTask.php and a ScheduleRunTask.php, it's my ProcessTask that once ran will grab entries from a database table, loop over them and do something. I cannot use Supervisor for the project I'm working on as this is a strict prerequisite.
The issue I face is that I need it to run automatically, and ideally need it to automatically scale up and down based on a settings table setting called something like "max workers" so that it's not always running 10 commands at once when it doesn't need to.
I've put together a crontab which runs my scheduler once a minute:
* * * * * cd /path-to-project-app && Console/cake queue_manager schedule_run >> /dev/null 2>&1
When this runs the schedule_run task, this in turn fires up the process task and runs these:
<?php
class ScheduleRunTask extends AppShell {
/**
* Main execute task
*/
public function execute() {
$maxWorkers = 5;
$currentWorker = 0
while ($currentWorker < $maxWorkers) {
exec("cd /path-ro-my-project-app && Console/cake queue_manager process", $output, $retval);
$this->out("<info>Worker is running.</info>");
}
}
}
But is this the best way to do this and do these run in their own processes? Which is important.
How do I prevent it from starting up another 5 exec commands on the next minute the cron runs, I'd end up with hundreds right?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
