Faveo Application has various jobs that need to be scheduled and run using cron or task schedulers. All these jobs can be processed using individual artisan command as well as single artisan command for running scheduled jobs.
Admin can select the frequency and time interval for running all these jobs from cron settings page. Admins can see all the available cron jobs which need to be set on the server and choose how frequently they want to run these jobs for their system. For example, Faveo needs to fetch mails from the mail server to generate tickets which are coming to users support email address and send escalation emails for violation of SLA on the tickets. Server Admin can do two things
- Set crons for artisan commands in crontab for fetching mail and sending SLA escalations and specify the frequency of each cron job individually.
- Set a single cron command “schedule:run” to run all jobs using single cron and specify frequency to run this cron on the server. And select the frequency to run different jobs from the application itself.
Please note in 2nd case execution of individual commands may not take place as the execution of the main command is set on the server and might conflict in the execution settings set in the application by admin.
Eg1. If cron is running every 5 minutes and admin has set up email fetching job to run every 1 minute from cron settings. Email fetching will only happen in 5 minutes instead of every minute as the main cron will only execute in 5 minutes.
Eg2. If cron is running daily at 10:00 AM on the server and admin has set up some jobs to run daily at 5:00 PM those jobs will never run as main cron execution time and execution time set by admin for these jobs are different. (Need to discuss how to handle this case and show user logs like WHMCS cron shown by Bhanu the other day).
Development of scheduled jobs for custom plugins
If you are to implement some modules or features using a custom plugin or package; which requires running some scheduled command then you do not need to make any changes in the Core Faveo code. Just register all custom commands in your plugin directory itself. An example of this has been implemented in the LDAP plugin. Console/Kernel class will execute the system’s active jobs and all active plugin’s active jobs implicitly.
Developers do not have to worry about how to add settings for their plugin jobs in Faveo cron settings. It will be visible in cron settings when the plugin is active. All they have to do is create an entry for all their custom jobs in the `conditions` table specifying the following attributes.
- Job: LDAP (single word name of your job)
- Value: everyMinute (the default value for execution time for their command)
- Icon: fa fa-clock (Font awesome icon class to show in the cron settings page for their job)
- Command: ldap:sync (artisan command for their job)
- Job_info: ldap-sync-info (Single-word for job description which will be fetched from language to show as a tooltip in cron settings page)
- Active: 1 (active/inactive status of the job )
- Plugin_job: 1 (Must be set as 1 to tell the system the job is custom plugin’s job otherwise)
- Plugin_name: Ldap (Must contain your plugin Directory name as it will be used to fetch language from your plugins lang directory, null otherwise)
Job and job_info word must be included in the lang directory of your plugin and plugin_name must be given as your plugin directory name as it will be used to render translation for Job and job_info in the cron settings page.
Things developer needs to complete
- Create an entry for their scheduled job commands only when the plugin is activated the first time.
- Create command in your plugin directory and register it in plugin’s ServiceProvider.
- Make sure there is not any hidden scheduled command(task) created for the plugin so always create an entry for any new scheduled command in
Please check App\Model\MailJob\Condition and App\Console\Kernel classes to check available useful methods. Also, check the article to develop scheduled task in custom Laravel package