7.0 KiB
Cron Job Setup for JobifyGarden
Since your hosting provider doesn't have Supervisor, you'll use cron jobs to handle scheduled tasks and queue processing.
Prerequisites
- SSH access to your server
- Access to crontab configuration
- Verify your application path (likely
/home/jobifyg/public_htmlor similar)
Setup Instructions
Step 1: Make Queue Worker Script Executable
cd /home/jobifyg/public_html
chmod +x queue-worker.sh
Step 2: Configure Crontab
Edit your crontab:
crontab -e
Add these lines (replace /home/jobifyg/public_html with your actual path):
# =============================================================================
# JobifyGarden Cron Jobs
# =============================================================================
# Laravel Scheduler - REQUIRED
# Runs every minute to process scheduled commands
* * * * * cd /home/jobifyg/public_html && php artisan schedule:run >> /dev/null 2>&1
# Queue Worker - REQUIRED
# Option 1: Using the helper script (recommended)
* * * * * /home/jobifyg/public_html/queue-worker.sh
# Queue Worker - Option 2: Direct command (if script doesn't work)
# * * * * * cd /home/jobifyg/public_html && php artisan queue:work --max-time=50 --stop-when-empty --sleep=3 --tries=3 >> storage/logs/queue.log 2>&1
# Queue Restart - OPTIONAL but RECOMMENDED
# Restarts queue workers every hour to prevent memory leaks
0 * * * * cd /home/jobifyg/public_html && php artisan queue:restart >> /dev/null 2>&1
# Clear old failed jobs - OPTIONAL
# Clears failed jobs older than 7 days, runs daily at 4 AM
0 4 * * * cd /home/jobifyg/public_html && php artisan queue:flush >> /dev/null 2>&1
Step 3: Verify Cron Jobs Are Running
After saving your crontab, verify it's active:
# List your cron jobs
crontab -l
# Check if cron jobs are running (wait a few minutes)
tail -f /home/jobifyg/public_html/storage/logs/laravel.log
# Check queue worker logs
tail -f /home/jobifyg/public_html/storage/logs/queue-worker.log
What Each Cron Job Does
1. Laravel Scheduler (* * * * * ... schedule:run)
Frequency: Every minute
Purpose: Checks and runs scheduled tasks defined in bootstrap/app.php
Scheduled Tasks:
jobs:fetch- Fetches new jobs from APIs every 2 hoursjobs:enrich- Auto-categorizes and enhances jobs every 6 hoursjobs:clean- Removes old jobs (45+ days) daily at 2 AMjobs:deduplicate- Removes duplicate jobs daily at 3 AMcache:prune-stale-tags- Cleans cache hourly
For detailed explanations and customization options, see SCHEDULED_TASKS.md
2. Queue Worker (* * * * * ... queue:work)
Frequency: Every minute Purpose: Processes background jobs from the queue
Jobs Processed:
- Fetching jobs from external APIs
- Processing individual job listings
- Email notifications (if configured)
- Cache warming
- Other background tasks
Options Explained:
--max-time=50- Worker runs for max 50 seconds then exits--stop-when-empty- Exits if no jobs are in queue--sleep=3- Waits 3 seconds between jobs--tries=3- Retries failed jobs up to 3 times
3. Queue Restart (0 * * * * ... queue:restart)
Frequency: Every hour Purpose: Gracefully restarts queue workers to prevent memory leaks
4. Queue Flush (0 4 * * * ... queue:flush)
Frequency: Daily at 4 AM Purpose: Clears old failed jobs from the database
Troubleshooting
Cron jobs not running?
-
Check crontab is saved:
crontab -l -
Check PHP path:
which php # Use the full path in crontab if needed: /usr/bin/php artisan ... -
Check application path:
pwd # Make sure you're using the correct path in crontab -
Check file permissions:
ls -la /home/jobifyg/public_html/artisan chmod +x /home/jobifyg/public_html/artisan
Jobs not being processed?
-
Check queue worker logs:
tail -f storage/logs/queue-worker.log -
Check Laravel logs:
tail -f storage/logs/laravel.log -
Manually run queue worker to see errors:
php artisan queue:work --verbose -
Check failed jobs:
php artisan queue:failed -
Retry failed jobs:
php artisan queue:retry all
Jobs are fetched but not appearing?
-
Check if job fetch is scheduled:
php artisan schedule:list -
Manually test job fetching:
php artisan jobs:fetch --limit=5 -
Check queue:
php artisan queue:work --once --verbose
Performance Tuning
Low Traffic Site
If your site has low traffic, you can reduce frequency:
# Run queue worker every 5 minutes instead
*/5 * * * * cd /home/jobifyg/public_html && php artisan queue:work --max-time=240 --stop-when-empty --sleep=3 --tries=3 >> storage/logs/queue.log 2>&1
High Traffic Site
If you need faster job processing:
# Run multiple queue workers
* * * * * cd /home/jobifyg/public_html && php artisan queue:work --max-time=50 --stop-when-empty --queue=high,default --sleep=1 --tries=3 >> storage/logs/queue-worker-1.log 2>&1
* * * * * cd /home/jobifyg/public_html && php artisan queue:work --max-time=50 --stop-when-empty --queue=default --sleep=1 --tries=3 >> storage/logs/queue-worker-2.log 2>&1
Monitoring
Check Cron Execution
Your hosting control panel may have a cron job log. Check there for execution history.
Check Application Health
# Visit this URL in your browser (Laravel health check)
https://jobifygarden.com/up
# Check recent jobs
php artisan tinker
>>> \App\Models\Job::latest()->take(5)->get(['id', 'title', 'created_at']);
Monitor Logs
# Watch all logs in real-time
tail -f storage/logs/*.log
# Check for errors
grep -i error storage/logs/laravel.log | tail -20
Important Notes
-
Queue Worker Must Keep Running: The queue worker cron ensures jobs are processed continuously. Without it, jobs will queue but never execute.
-
Schedule Must Run Every Minute: The scheduler cron must run every minute. Laravel internally determines which scheduled tasks should run.
-
Time Zone: Make sure your server's timezone matches your Laravel app timezone (check
config/app.php). -
Testing: After setup, wait a few minutes and check logs to verify everything is working.
-
Production: Make sure
APP_ENV=productionandAPP_DEBUG=falsein your.envfile.
Quick Test
After setting up cron, test immediately:
# 1. Manually run scheduler
php artisan schedule:run
# 2. Queue a test job
php artisan jobs:fetch Remotive --limit=2
# 3. Process the queue
php artisan queue:work --once --verbose
# 4. Check if jobs were created
php artisan tinker
>>> \App\Models\Job::count();
Support
If you encounter issues:
- Check the troubleshooting section above
- Review logs in
storage/logs/ - Ensure Redis is working:
php artisan tinkerthenCache::get('test') - Verify database connection works