I’m a little stuck on how to structure the files/folders. At the moment I have the following in my config.php
return [
'autopublish' => 'autopublish',
'debug' => true,
'bvdputte.kirbyqueue.queues' => [
'publish' => function ($job) {
// Get your data
$homepage = page('home');
$foo = $job->get('foo');
$bar = $job->get('bar');
// Do something with your data, for example: send something to kirbylog
try {
kirbylog("test")->log($homepage, $foo . " " . $bar);
} 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.
}
// No need to return or display anything else!
}
],
];
When I manually run the worker file at
.../site/plugins/kirby-fingerprint/worker.php
nothing happens. No error is thrown and no log file is created.
Maybe I’m missing some extra setup with the Queue plugin?
Hey @geodude, I’m sorry for the late reply. I’m currently on holiday and have only intermittent access to my laptop. Could you also post the contents of your worker.php please?
You’ve defined a queue, and a worker. You now have to add jobs to the queue somewhere where the event happens that you’ld like to add to the queue. Usually this is in a controller. Did you set this up somewhere already and did you run it whilst testing if your queue works?
When your queue is empty, it’s by design that the worker does nothing.
Okay I’ve created the controller file and added the example code, replacing the queue name so I’m using the one I created. I then ran the worker file with php and nothing happened.
Hi, do you have a “publish” template too? And do you have a page in content of the type publish? And have you visited that page so that the controller has at least run once?
You’re right. I really should work on the documentation.
Concerning the “controller” remark: creating docs can happen anywhere really… I just gave you the most typical place where I’ld put them (in a controller). I’ll add it to the docs and hopefully it makes things more clear