Problem/Motivation
There's no way to specify a different lease time for queue items than the lease time used for the whole queue. There's a bug in the Drupal Cron service currently which results in queue items always being reserved for only 1 second (see #3230541). Once this bug has been fixed, the cron-time specified for a queue should be used for total queue lease times and queue item lease times.
This is, however, less than ideal since there are cases where a developer may want to reserve queue items for longer than the over-all queue. For example, if someone had a queue worker which might process an item for up to 5 minutes, but didn't want to continue picking up new items after 3 minutes.
Proposed resolution
Separate queue worker annotations should be used for for a queue's time-limit and for the lease time for queue items.
A new "lease_time" annotation could be created which allows for specifying queue item lease times.
Use of the new annotation would look something like this:
<?php
namespace Drupal\slow_queue\Plugin\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
/**
* Sleep for 5 minutes and then log a message to watchdog.
*
* @QueueWorker(
* id = "slow_queue",
* title = @Translation("This queue worker processes items slowly and logs a message in watchdog when it's finished"),
* cron = {
* "time" = 30,
* "lease_time"=60
* }
* )
*/
class SlowQueueWorker extends QueueWorkerBase {
/**
* {@inheritdoc}
*/
public function processItem($item) {
\Drupal::logger('slow_queue')->notice('Starting: ' . $data);
sleep(60);
\Drupal::logger('slow_queue')->notice('Done: ' . $item);
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3274931-9.patch | 8.09 KB | _utsavsharma |
| #9 | interdiff_8-9.txt | 471 bytes | _utsavsharma |
| #8 | cron_lease_time-3274931-8.patch | 8.09 KB | jastraat |
| #7 | cron_lease_time-32749317.patch | 8.09 KB | jastraat |
| #5 | 3274931-5.diff | 7.56 KB | cliddell |
Issue fork drupal-3274931
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #5
cliddell commentedComment #7
jastraat commentedRolling a patch for Drupal 9.5.x.
Comment #8
jastraat commentedRe-rolling for syntax violation
Comment #9
_utsavsharma commentedFixed CCF for #8.
Please review.
Comment #11
mile23