kirby-queue icon indicating copy to clipboard operation
kirby-queue copied to clipboard

PMC bugs

Open squareclouds opened this issue 2 years ago • 0 comments

hello,

i am using php 8.1 and kirby 3.8 (dont know if other versions are behaving the same way) and i found that, that the cron function was not working for me:

if (option("bvdputte.kirbyqueue.poormanscron")) {
    $root = kirby()->roots()->site() . '/' . option("bvdputte.kirbyqueue.root");
    $pmcFile = $root . "/.pmc";

    if (!f::exists($pmcFile)) f::write($pmcFile, time());
    $nextRun = f::read($pmcFile) + option("bvdputte.kirbyqueue.poormanscron.interval");

    if( $nextRun < time() ) {
        // Work the queue
        bvdputte\kirbyQueue\Queueworker::work();
        f::write($pmcFile, time());
    }
}

after changing

option("bvdputte.kirbyqueue.root");

to

kirby()->option("bvdputte.kirbyqueue.root");

it started working. so technically the complete IF looks like this:

if (option("bvdputte.kirbyqueue.poormanscron")) {
    $root = kirby()->roots()->site() . '/' . kirby()->option("bvdputte.kirbyqueue.root");
    $pmcFile = $root . "/.pmc";

    if (!f::exists($pmcFile)) f::write($pmcFile, time());
    $nextRun = f::read($pmcFile) + kirby()->option("bvdputte.kirbyqueue.poormanscron.interval");

    if( $nextRun < time() ) {
        // Work the queue
        bvdputte\kirbyQueue\Queueworker::work();
        f::write($pmcFile, time());
    }
}

also, I had to set these options inside the plugin index.php, otherwise from the config.php it was not working either. strangely enough, the 'worker.route' works from the config, but i guess it is because it is called later?

options i had to set in index of plugin

'poormanscron' => true,
'poormanscron.interval' => 30, // in seconds

squareclouds avatar Nov 11 '22 10:11 squareclouds