Advice on setting up Queue & Logging Plugins

Hi,

I’m looking to set up the following plugins:

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?

Any help would be much appreciated!

@bart to the rescue?

@bvdputte Would you be able to provide an example of the file structure required to get these plugins working?

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?

No worries. Thanks for taking a look while on your holiday.

<?php

use bvdputte\kirbyQueue\Queueworker;

// Bootstrap Kirby (from with the plugin's folder)
require __DIR__ . '../../../../kirby/bootstrap.php';
$kirbyPath = dirname(__FILE__) . "/../../../../";

// Instantiate Kirby
$kirby = new Kirby([
    'options' => [
        'debug' => true,
    ],
    'roots' => [
        'kirby' => $kirbyPath
    ],
]);

// Work the queue
Queueworker::work();
exit();

Alright, excellent.

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.

Am I missing something?

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?

Woohoo. Just did what you said and the output is now showing in the queues directory.

Are these yml files the logs produced by Kirbylog? I expected to see the logs outputted to a different dir…

Hi, the yaml files are the “jobs”. The worker should actually work down this folder until there are no jobs (== yaml files) left inside it.

So, if you should start the worker now, the logs should be generated.

1 Like

Awesome. That’s all working now! Thanks for you help and kudos for developing this two plugins, super useful!

1 Like

You’re welcome. Thanks for getting back and letting us know it’s all ok now.

1 Like

I just noticed you’ve pinged the wrong Bart @texnixe :slight_smile:

Could I suggest that you add a little more clarity around this section of the docs?

Maybe just mention that these calls can go in controllers?

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 :+1:

1 Like