Skip to main content
Skip to main content
🚧 Work in Progress

Scheduled Tasks and CRON Jobs

Zerops provides a convenient way for managing scheduled tasks through CRON jobs, configured directly in your zerops.yml file. These tasks can be scheduled to run on single or multiple containers with granular timing control.

Basic Configuration​

Cron jobs are defined in the run.crontab section of your zerops.yml. Each job requires two essential parameters:

  • command: The command to execute
  • timing: The CRON schedule expression
run: 
crontab:
- command: "date >> /var/log/cron.log"
timing: "0 * * * *"

This example logs the current timestamp every hour.

Detailed Configuration

For comprehensive configuration options and examples, refer to our CRON configuration guide.

Common Implementation Patterns​

Laravel Scheduler​

To run Laravel's scheduler, configure it to execute every minute:

run: 
crontab:
- command: "php artisan schedule:run"
timing: "* * * * *"
workingDir: /var/www/html

Cleanup Tasks​

Execute maintenance tasks on all containers:

run: 
crontab:
- command: "rm -rf /tmp/*"
timing: "0 0 * * *"
allContainers: true

Multiple Jobs​

Configure multiple scheduled tasks within a single service:

run:
crontab:
- command: "php artisan schedule:run"
timing: "* * * * *"
workingDir: /var/www/html

- command: "php artisan cache:clear"
timing: "0 0 * * *"
workingDir: /var/www/html

- command: "php artisan queue:restart"
timing: "0 */6 * * *"
workingDir: /var/www/html

Best Practices​

  1. Log Output: Implement comprehensive logging for debugging and monitoring:

    command: "php artisan schedule:run >> /var/log/scheduler.log 2>&1"
  2. Working Directory: Always specify workingDir for Laravel commands to ensure they are executed from the correct location.

  3. Container Selection: Use allContainers: true carefully to avoid duplicate operations in a multi-container setup.

  4. Timing Considerations: Schedule intensive tasks during off-peak hours.

Monitoring​

Enable detailed scheduler logging in your .env:

LOG_CHANNEL=daily