I am trying to set up a queue to process some images after saving a page.
In my /site/config/config.php, I have the following:
return [
'debug' => true,
'bvdputte.kirbyqueue.queues' => [
'generate_tiles' => function ($job) {
try {
// JOB LOGIC HERE
} catch (Exception $e) {
// Throw an error to fail a job
throw new Exception($e->getMessage());
// or just return false, but setting a message for the user is better.
}
}
],
'hooks' => [
'page.update:after' => function ($newPage) {
if ($newPage->blueprint()->title() == 'Work') {
$queue = kqQueue("generate_tiles");
$job = kqJob([
'page' => $newPage
]);
$queue->addJob($job);
}
}
]
];
I’m wondering if, first of all, the config is the right place to put this?
Then I am always getting an error on saving: Exception: Error Call to undefined function kqQueue() which I am chalking up to having installed via composer require bvdputte/kirby-queue, which is placing the files in vendor/bvdputte/kirby-queue rather than /site/plugins/kirby-queue.
What is the right way to correct this (other than manually moving the files or another installation method?)
@bvdputte I would really appreciate a nudge in the right direction, thank you for this plugin!
However, I tried this in a new starterkit, and this worked, although I had to change
$job = kqJob([
'page' => $newPage
]);
into
$job = kqJob([
'page' => $newPage->id()
]);
because of “maximum nesting reached” error. But if you store the id, you can easily fetch the page in the job handler.
Unfortunately, I don’t use composer so I didn’t test it with composer. I suggest you try it with manually putting it in the plugins folder and go from there? Or maybe a composer whizzkid can help you out?
Thanks for the response @bvdputte - you’re right about the problem with the job code. So it does indeed work if I manually copy the plugin to the site/plugins directory, but was wondering if maybe @texnixe knows why or how a plugin knows to be installed to the plugins directory?
I’m deploying with something that runs composer so ideally it would be possible to fix!
@bvdputte You should do another plugin release. The required kirby-plugin type was added on master after the 1.0.1 release, so Composer does not already pick it up when version 1.0.1 gets installed. With the type it should work.