- 🇨🇦Canada liquidcms
from #10:
<ul> <li> In your custom module at module_name/config/optional add a file in the format ultimate_cron.job.cron_job_name.yml</li> <li> Create a config file in line with the code example below.</li> <li> Clear your sites caches and import your config.</li> <li> If the cron job is not showing up in the cron list after hitting 'Discover Jobs' try either importing the config item by copy/paste under 'Configuration Synchronization' and hitting 'Discover Jobs' again. </li> </ul>
it mentions import your config. How do you do that (with drush) when adding to already enabled module? I assume i need to manually import it with CMI UI? Drush cim or cr won't do this. This isnt a very deployable solution.
and in the patch from #22:
+To add a cron job you can use either hook_cron() or use configuration files with custom parameters +for multiple/additional cron jobs in a module. + +The easiest way to declare a cron job is tu use hook_cron() +and then configure the cron job through the UI and export it, then change the cron jobs callback method.
does this work? How? Same as D7? But it isnt functional on its own, you need to export and then modify through UI? Does that make sense? If you export (not sure what callback is to start with) and then change in UI, when you import again it will be reset.
I feel like in general this module is somewhat backwards from typical modules. It seems like it requires manually creating config files to create config and then importing these. Isn't a more standardized approach to have the UI create cron jobs? Add the callback there. Then, like normal, we'd do cex and this would dump the config file. Just a thought.
- 🇨🇦Canada liquidcms
the discover jobs seems like a reasonable work around to not having a UI to add cron jobs:
- make module config file
- discover jobs
- cexexcept discover jobs doesn't work to find new jobs added to config of an already enabled module - not sure what it does.
- 🇨🇦Canada liquidcms
This is what i have ended up with:
- add config file to custom/mymodule/config/optional/ultimate_cron.job.cron_job_name.yml
- also add this file to config/sync
- drush cim
- modify in UI if needed
- drush cexNOTES:
- adding to your config/optional is only for a module which has not yet been enabled; after that it isn't used for anything
- make sure cron_job_name in your yml file name matches the callback function as cex uses that to create the config file. If not named the same then you will now have 2 config files in config/sync for the same cron job and will fail when doing cim - 🇩🇪Germany kreatIL
I managed to get it running by:
- uninstall my custom module containing the callback function
- add config file to custom/mymodule/config/optional/ultimate_cron.job.cron_job_name.yml
- re-install my custom module
The cron job appeared in the list of jobs under /admin/config/system/cron/jobs even without triggering "Discover jobs".
- edit job configuration
- drush cex - 🇨🇦Canada liquidcms
@kreatIL
"uninstall my custom module containing the callback function" - this is not always (even rarely) possible though.
- 🇨🇦Canada liquidcms
I am starting to get the sense (although very hard to tell from documentation) that hook_cron() might enable defining new cron tasks. The patch to README here even stats: "To add a cron job you can use either hook_cron() "
but sadly it give no details on how to do this. :(