[5.x]: Thousands of Generating catalog pricing jobs
What happened?
Description
We have a import running at night, since the upgrade that introduced the "Generating catalog pricing job", it taks a loooong time to finish, adding thousands of jobs because we have many products. It disrupts daily operations, where in the past it was finished at night.
Can we have a batch mode/flag/setting to disable the listener? So we can manually batch generate them after the last job finished?
Craft CMS version
5.x
Craft Commerce version
4.x
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
Hi @lenvanessen
Thank you for your message.
As these queue jobs are being generated from your custom import you have the ability to prevent them from being added and handle the generation yourself.
In you custom code where you are importing your products, just before the saving of the product element, you can prevent the catalog pricing job from being added to the queue.
That can be done with the following code:
Event::once(Queue::class, Queue::EVENT_BEFORE_PUSH, function(PushEvent $event) {
if ($event->job instanceof CatalogPricing) {
$event->handled = true;
}
});
// Save your product
An important point to note is that by not running the jobs during your sync process it would be required to run the catalog pricing generation after you have finished saving everything. You can do that with the following code:
Plugin::getInstance()->getCatalogPricing()->generateCatalogPrices();
Generating the prices all at once at the end shouldn't be too tasking.
We are currently looking into seeing if we can merge pricing jobs together (similar to how search indexing jobs work), so there will be an improvement on this in the future. For that reason I will leave the issue open.
Thanks!