Question on setting up kirbyqueue

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!

Hi, I never tried it in a hook tbh.

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!

I just tested this with a fresh composer setup as described here:

Then it cd’d into the folder and first ran

composer require distantnative/search-for-kirby

which correctly installed the search plugin into the site folder

Then I did the same with the kirby-queue plugin, but it ended up in the vendor folder.

I first thought the type was missing from composer.json, but it’s there. :thinking:

There’s reasonable chance that I messed up something about composer in the plugin…

I think I followed the plugin guidelines as good as possible, if someone can help me out about this, please do!

@bvdputte Your kirby-floc-off plugin installs correctly, so does vpkit

I’m at a loss…

Let’s ask our Composer expert @lukasbestle, ping!

Thanks. I’m afraid I’m lost too.

The composer.json file looks similar. I did notice this in the index.php: kirby-queue/index.php at 662a8f8d1c9a8a58717cb85bdc4a7b0c81e2fa0e · bvdputte/kirby-queue · GitHub ?

That line is unnecessary, since you are not requiring any dependencies via composer but manually loading your files.

@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. :slight_smile:

3 Likes

Oh boy :see_no_evil:

I have drafted a new release, can you try again @waffl ?

Thx @lukasbestle & @texnixe !

1 Like

Works now!

1 Like

Thx for confirming @texnixe !

Yes, it works! Wow thank you all for the help, I was also confused when comparing the composer.json against other plugins that worked.

Thank you all and thank you again @bvdputte for this great plugin :slight_smile:

1 Like