craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 627 forks source link

[4.x]: Queue tasks aren't running until CP is hit by a user #11832

Closed turnstylerj closed 2 years ago

turnstylerj commented 2 years ago

What happened?

Description

I have a cron job set to process a large feed with the Feed Me plugin, scheduled to run overnight when less people will be using the site. The task is getting queued up, but the feed is not actually processing until a user hits the CP in the morning, so it defeats the purpose of scheduling it when nobody's using the CMS.

I filed this issue with the Element Relations plugin a while back, but it feels like this might be the same thing going on and it's more related to Craft than either plugin.

Steps to reproduce

  1. Schedule a cron job to execute a task that gets added to the queue
  2. Access the CP after the task should have run and completed

Expected behavior

The task will have run and completed prior to accessing the CP

Actual behavior

The task begins running once the CP is accessed

Craft CMS version

4.2.2

PHP version

8.1.3

Operating system and version

Linux 4.15.0-163-generic

Database type and version

MySQL 8.0.23

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-26)

Installed plugins and versions

"craftcms/aws-s3": "2.0.1", "craftcms/feed-me": "5.0.4", "craftcms/redactor": "3.0.2", "doublesecretagency/craft-cpcss": "2.5.0", "fortrabbit/craft-copy": "^2.1", "internetztube/craft-element-relations": "2.0.0", "mmikkel/retcon": "2.5.0", "nystudio107/craft-imageoptimize": "4.0.2", "nystudio107/craft-minify": "4.0.0-beta.2", "nystudio107/craft-retour": "4.0.2", "nystudio107/craft-seomatic": "4.0.7", "percipioglobal/craft-colour-swatches": "4.2.0.1", "spicyweb/craft-neo": "3.3.5", "verbb/field-manager": "3.0.2", "vlucas/phpdotenv": "^5.4.0", "weareferal/matrix-field-preview": "4.0.3"

brandonkelly commented 2 years ago

This is expected behavior out of the box. If you want the queue to be run regularly, you need to create a daemon that runs the following command:

php craft queue/listen

Or a cron job that runs the following command every minute:

php craft queue/run

Then disable the runQueueAutomatically config setting, so Craft stops running the queue during control panel requests.