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.
Problem/Motivation
drupal_cron_run()
invokes hook_cron_queue_info()
hooks and processes items registered there by passing queue items data to a worker (worker callback
). But the invoking code (drupal_cron_run()
) it only allows passing of procedural functions not callables in the general meaning of http://php.net/manual/language.types.callable.php.
This is bug that prevent using of class methods as worker callbacks.
Proposed resolution
Change drupal_cron_run()
to allow REAL worker callbacks.
Remaining tasks
- Patch
- RTBC
- Commit
User interface changes
None.
API changes
Developers are able now to pass a callable as worker callback
in hook_cron_queue_info()
.
Comment | File | Size | Author |
---|---|---|---|
#18 | 2342667-cron-and-batch-callables.patch | 3.83 KB | Dave Reid |
#15 | cron_and_batch-2342667-15.patch | 3.95 KB | claudiu.cristea |
Comments
Comment #1
claudiu.cristeaPatch
Comment #2
dcam CreditAttribution: dcam commentedThere is duplication of work between this issue and #2309539: Inconsistency in callback processing. The patches should be merged and one of the issues should be closed. Normally, the newer issue (this one) is the one that should be closed.
Comment #3
claudiu.cristeaEach occurence needs to ne researched and treated separately because it depends on specific context. I wouldn't mix them in a single issue. Moreover, I don't have time resouces to tackle that ticket. This just pop up because of a specific project where I needed this. So, from my point of view it's a "take it or leave it".
Comment #4
MiroslavBanov CreditAttribution: MiroslavBanov commented@claudiu
If there is interest in the community, someone will tackle the ticket.
Comment #5
claudiu.cristeaOK. Here's a patch including the batch processing and I added also a test. I will close the other one because my last patch is continuing this one.
@dcam, can you please review this? Thank you!
Comment #6
claudiu.cristeaComment #9
claudiu.cristeaRerolled.
Comment #10
David_Rothstein CreditAttribution: David_Rothstein commentedNot sure the above is needed, although otherwise the patch looks good.
However, is this patch even necessary? At least on PHP 5.4, this seems to work fine:
And if I run the tests on PHP 5.4 they pass even without the rest of the patch...
I can't seem to find clear documentation of this behavior on php.net though. Will the tests fail (without the rest of the patch) in earlier versions of PHP or something?
Comment #11
claudiu.cristeaHere are some manual tests:
PHP 5.4
PHP 5.3
The lazy loader, yes, we don't need that.
EDIT: Removed version copyright info for readability reasons.
Comment #13
ndobromirov CreditAttribution: ndobromirov commentedIn the part of the patch:
Needs to check is_callable instead of function_exists, as the later is invalid for lambda functions and class methods.
Comment #14
ndobromirov CreditAttribution: ndobromirov commentedComment #15
claudiu.cristeaPatch.
Comment #16
claudiu.cristeaComment #17
Dave ReidComment #18
Dave ReidRe-rolled for CHANGELOG.txt.
Comment #19
claudiu.cristea@Dave Reid, as you only made a reroll without providing a patch it would be nice if you can provide a review or... RTBC. This issue is here for a long time :)
Comment #20
Dave ReidI didn't believe I can RTBC my own patch, even if it is a reroll.
Comment #21
ndobromirov CreditAttribution: ndobromirov commentedSeems good.
Tests are passing, the code makes no regressions and provides only enhancements.
Marking it as RTBC.
Comment #22
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedCommitted to 7.x - thanks!
Not sure if we should expand some of the documentation, e.g. hook_cron_queue_info(), to highlight this too. Although since this is only something core supports right now (no guarantee any already-written code elsewhere that invokes the same hook supports it) maybe it's better to leave this as is and just have it as a semi-hidden feature for the time being.
Comment #24
ndobromirov CreditAttribution: ndobromirov at FFW commentedComment #25
Dave Reid