Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
QueueInterface::claimItem returns useful data about the queued item in addition to the actual data that was queued:
* If returned, the object will have at least the following properties:
* - data: the same as what what passed into createItem().
* - item_id: the unique ID returned from createItem().
* - created: timestamp when the item was put into the queue.
In particular, the 'created' timestamp is potentially useful.
However, the cron queue processor throws this away and gives us just the data:
while (time() < $end && ($item = $queue->claimItem($lease_time))) {
try {
$queue_worker->processItem($item->data);
This is nice DX, as queue worker plugin don't need to unserialize it and you get the same thing in your queue worker's processItem() as you put into createItem(), but information is lost.
One way to fix this would be for processItem() to receive the complete item as as second parameter.
Comments
Comment #13
solideogloria CreditAttribution: solideogloria commentedI agree. I have a use-case where it could be solved if I had the entire
$item
as a second parameter.I have implemented a MergeDatabaseQueue to avoid duplicate queue items:
However, in one case, I also need to track the time the item was queued, so that the item is only processed if it is older than a week. If I track that as part of the data that is serialized, the item will no longer be mergeable with any other item having the rest of the data the same. What I really need is to be able to view the
created
field inside the worker'sprocessItem
function, rather than having to include it in the serialized data.Comment #14
solideogloria CreditAttribution: solideogloria commentedIf you use ultimate_cron, this is a hacky workaround:
my_module.services.yml
Queue config, ultimate_cron.job.ultimate_cron_queue_my_module_some_queue.yml