I know that this could be considered a subjective question, but I think it's important. (I do produce Joomla documentation for extension developers and it would be useful to relay answers to them).
In Joomla 3 you would write a CLI job which was based on
JApplicationCli. You would package it up in a
file type install, and set up a cron job to run it automatically.
In Joomla 4 the
JApplicationCli (aka Joomla\CMS\Application\CliApplication) class is deprecated with an indication "Use the ConsoleApplication instead".
How to develop a console application is described at https://docs.joomla.org/J4.x:Writing_A_CLI_Application and you can develop applications which can be run from a command line or a cron job:
php cli/joomla.php mycommand:task
So far, all is fine.
However, Joomla 4 also includes a task scheduler. You can write a task and configure when it should be run (or you can click a Run button to run it immediately). The task scheduler then acts a little like cron and runs the task automatically, albeit that the scheduler needs some sort of trigger to kick it off, eg a separate cron job or visitor traffic on this website.
I updated a Joomla 3 CLI job using both approaches. (The job queried some database records and sent an email with the results). The approaches are similar in that:
- both require a plugin, which must respond to an event to indicate that the task I've written is available
- both have a mechanism to define and obtain task configuration options
- with both you write a function which performs the task you want
However the approaches are different enough to make it a bit of a challenge to avoid duplicating code between the two.
Hence the question of how do the approaches fit together, if at all. When should one approach be used instead of the other?
I understand that one answer could be: well, Joomla gives you the choice.
But then, whose choice is this, the extension developer's or the Joomla website administrator?
If it's the developer's choice then an administrator could end up with some jobs to manage as cron jobs, and others to manage via the task scheduler.
If it's the administrator's choice then it seems to me that extension developers would be expected to develop both options.