Problem/Motivation

All hooks have to invoke via the 'module_handler' service. If it isn't call via the call_user_func function.
I ran into a problem when hook_cron invisible for the Ultimate Cron.

Steps to reproduce

  1. Install the Hux module.
  2. Add hook_cron via attribute (like write in README of the Hux module). Make sure that this issue was merged or just apply patch.
  3. Click Discover Job button
  4. Try to run this cron.

Proposed resolution

We have to check if it hook and invoke via the 'module_handler' service.

Command icon 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

miroslav-lee created an issue. See original summary.

miroslav-lee’s picture

Status: Active » Needs review
miroslav-lee’s picture

Issue summary: View changes
berdir’s picture

Version: 8.x-2.0-alpha6 » 8.x-2.x-dev
Status: Needs review » Needs work

Related issues: #3274089: hook_event_dispatcher compatability and #3414863: Support CronSubscribers (and the related core issue).

Interesting solution but it's trying to be a little bit too generic I think. Whether or not something is/has certain hook is just a naming convention, with that logic, any module-prefixed callback is going to be recognized as a hook.

Instead, we should do this only if it the cron hook. Meaning, isCallbackHook() should just check $this->getHookName() === 'cron', at this point we can of need to expect that it exists.

Hopefully, the long-term solution is the core issue that I created to make cron tasks/jobs their own thing that can be discovered and not hooks. Feedback/reviews there would definitely be welcome.

berdir’s picture

Status: Needs work » Closed (duplicate)

Drupal 11.1 now has #Hook, implemented something quite similar to this in #3489356: Support #Hook cron implementations including a new special syntax instead of assuming based on the function name, that would have worked too I guess, forgot about this issue actually.