daycry / cronjob

- Manage Cron jobs in Codeigniter 4
MIT License
64 stars 20 forks source link

feat: Implement `runInBackground` method for commands #39

Closed iamgabrieloliveira closed 3 months ago

iamgabrieloliveira commented 3 months ago

Description

$schedule->command('slow-command')->runInBackground()->hourly();

This PR adds an option to configure a scheduled command to run in the background. This feature is particularly useful for jobs that take a significant amount of time to complete, as it prevents subsequent scheduled jobs from being delayed.

Implementation Details

By default, commands are triggered by calling the CI helper:

command('command:name');

When a job is configured to run in the background, this default behavior is bypassed. Instead, the job is executed using the current shell execution:

/usr/bin/php spark command:name && cronjob:finish --name command:name --type command

Key Components:

Additionally, the cronjob:finish command is responsible for setting the cronjob status to "stopped," allowing it to run again without issues.

daycry commented 3 months ago

Hi! Tomorrow I will review your changes.

Thank you!