Only 1 worker per group on CakePHP Queue Plugin

I wrote some tasks using the CakePHP queue

My current config is:

    'workermaxruntime' => 0,
    'maxworkers' => 1,

My jobs are separated by group and I expect to have 1 and only 1 worker per group running 24/7. Is there any way to achieve this?

maxworkers is the total amount of workers which are allowed to be run on your whole server, no matter which group.

So if you have 4 groups of tasks which should be worked on in parallel this should be 4 so you can start 1 worker per group with bin/cake queue run -g Group1, bin/cake queue run -g Group2 etc.

As far as I can tell there is no limitation to only run 1 worker per group. You have to make sure this doesn’t happen by yourself.

What I like to do to prevent specific jobs being executed in parallel is to add a check like

$currentJob = $this->QueuedJobs->get($jobId);
$runningJobs = $this->QueuedJobs->find()
    ->where([
        'job_task' => 'MyTaskName',
        'reference' => $currentJob->reference,
        'workerkey IS NOT' => null,
        'id IS NOT' => $jobId,
        'completed IS' => null,
    ])
    ->first();

if ($runningJobs instanceof QueuedJob) {
    throw new \RuntimeException(__('Some telling message!'));
}

at the start of the task.

Depending on your set $retries property (and queue config) in the task this can then be refetched later again but you have to trial and error that for yourself.