This guide explains how to set up automatic scheduling for your sync commands to run early morning and late night in GMT+3 timezone.
The following sync commands are now scheduled to run automatically:
directorates:sync - Syncs directorates data from Africa CDC APIdivisions:sync - Syncs divisions data from Africa CDC API staff:sync - Syncs staff data from Africa CDC APIThe scheduler is already configured and working! You can verify it with:
# Test the schedule list
php artisan schedule:list
# Test a specific command
php artisan directorates:sync
php artisan divisions:sync
php artisan staff:sync
Add this cron job to your server's crontab to run the Laravel scheduler every minute:
# Edit crontab
crontab -e
# Add this line (adjust the path to your Laravel project)
* * * * * cd /opt/homebrew/var/www/staff/apm && php artisan schedule:run >> /dev/null 2>&1
If you prefer to set up cron jobs directly instead of using Laravel's scheduler:
# Edit crontab
crontab -e
# Early morning sync (6:00-6:10 AM GMT+3)
0 6 * * * cd /opt/homebrew/var/www/staff/apm && php artisan directorates:sync >> /var/log/sync-directorates.log 2>&1
5 6 * * * cd /opt/homebrew/var/www/staff/apm && php artisan divisions:sync >> /var/log/sync-divisions.log 2>&1
10 6 * * * cd /opt/homebrew/var/www/staff/apm && php artisan staff:sync >> /var/log/sync-staff.log 2>&1
# Late night sync (11:00-11:10 PM GMT+3)
0 23 * * * cd /opt/homebrew/var/www/staff/apm && php artisan directorates:sync >> /var/log/sync-directorates.log 2>&1
5 23 * * * cd /opt/homebrew/var/www/staff/apm && php artisan divisions:sync >> /var/log/sync-divisions.log 2>&1
10 23 * * * cd /opt/homebrew/var/www/staff/apm && php artisan staff:sync >> /var/log/sync-staff.log 2>&1
withoutOverlapping() - Prevents multiple instances from running simultaneouslyrunInBackground() - Runs commands in background to avoid blockingonFailure() - Logs errors if commands failAll sync operations are logged to Laravel's log files. Check logs at:
storage/logs/laravel.logYou can monitor the scheduler with:
# View scheduled tasks
php artisan schedule:list
# Test the scheduler
php artisan schedule:test
# Run the scheduler manually
php artisan schedule:run
# Check cron service status
sudo systemctl status cron
# Check cron logs
sudo tail -f /var/log/cron.log
# Test each command individually
php artisan directorates:sync
php artisan divisions:sync
php artisan staff:sync
# View recent logs
tail -f storage/logs/laravel.log
The scheduler is set to Africa/Nairobi timezone (GMT+3). Verify your server timezone:
# Check server timezone
date
timedatectl
.env file has the correct API credentialsIf you encounter issues: