Problem/Motivation

Should this module call discoverCronJobs() on cache rebuild rather than module install?

It means that if a developer adds a hook_cron() to a custom module, they won't get a cron job for it automatically.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

joachim created an issue. See original summary.

raushan’s picture

I am working on this issue.

raushan’s picture

Assigned: Unassigned » raushan
raushan’s picture

StatusFileSize
new633 bytes

Add hook_rebuild to implement this feature.

After clearing the cache discoverCronJobs() will run and Cron will be listed on the cron list page.

Thanks

raushan’s picture

StatusFileSize
new605 bytes

Added a new line at the end of the file.

Thanks

raushan’s picture

Status: Active » Needs review
raushan’s picture

Assigned: raushan » Unassigned
liquidcms’s picture

This would be excellent as the button on the cron admin page to "discover jobs" does nothing. Although, wouldnt we expect that it just runs the same command this patch is adding to cache rebuild? So possibly the question is what are these discovering?

OP mentions hook_cron but this is Core's hook for running cron tasks; nothing related to UC i wouldn't think. And there is nothing mentioned about hook_cron in ultimate_cron.api.php only a bunch of hooks which some other issues here have suggested are no longer supported. I do see a mention of hook_cron in the README; but no details.

So when i say neither this patch, nor the button on the admin page do anything i am referring to the only thing i have found suggesting how to add new cron tasks to a custom module:
- add exported config (chicken/egg issue) to custom_module/config/install/optional

of course this doesnt work well for modules which have already been enabled (as i think this patch is trying to address).

so i feel some documentation missing somewhere re-purposing core's hook_cron?

guiu.rocafort.ferrer’s picture

As far as i know, it goes as follows for hook_cron ( without the provided patch ):

1. When installing ultimate_cron, it will find all hook_cron implementations and create configuration objects for each one.
2. When installing a module which implements hook_cron, ultimate_cron will pick it up and create the configuration automatically.
3. When adding a new hook_cron to an already installed module, then the configuration will not be created automatically, not even cleaning caches. The "Discover jobs" button needs to be pressed.

When it comes to configuration objects, if you added a some cron configuration objects in config/install, and you want to add another one after the module is installed, then you have to write a hook_update to do that. This is not a ultimate_cron issue, but rather an issue with the module implementing the functionality, and it is also the case with other configurations that the module might add after it has been installed.

I tested the patch, and it discovers new hook_cron implementations when rebuilding the caches, so i would say it works as expected, and the issue can be closed. We might want to create a new issue on creating/updating the documentation about how the module works, but i would do it in a separate issue.

guiu.rocafort.ferrer’s picture

Status: Needs review » Reviewed & tested by the community
berdir’s picture

I'm not certain this is a good idea. This changes config, it's not just cached data, and could be unexpected. And it does exactly the same as the button in the UI.

guiu.rocafort.ferrer’s picture

The way i see it, external events, such as the install of a different module, are already triggering config changes in the ultimate_cron module, so i don't see why that would be different in the case of cache rebuilds. Without this functionality, a module that wants to start implementing a hook_cron would need to do one of the following:

  1. Implement a hook_update that triggers the discoverability of the new hook. I could not find any documentation at all about how to do this. The hook_update should be dependant on the fact that ultimate_cron is installed in the site too, if they don't list it explicitly as a dependency.
  2. ask the user to press the "discover jobs" button. not ideal in my opinion.

If we dedide on not implementing this, i believe that at least this should be documented, so module developers can implement a hook update to make ultimate_cron pick up the new hook, and create the corresponding configuration object.

  • berdir committed e5ebc7f5 on 8.x-2.x
    Issue #3317033 by raushan, guiu.rocafort.ferrer: discover cron jobs on...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

> The way i see it, external events, such as the install of a different module, are already triggering config changes in the ultimate_cron module, so i don't see why that would be different in the case of cache rebuilds.

installing a module implies configuration changes. a cache rebuild less so. But it should only do anything if code also changed, so fair enough. Merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.