The SchedulerUtil
in the LaraUtilX
package provides functionality for managing and monitoring scheduled tasks.
getScheduleSummary(): array
: Retrieves a summary of the scheduled tasks.hasOverdueTasks(): bool
: Checks if any scheduled tasks are overdue.Get Schedule Summary:
To retrieve a summary of the scheduled tasks, use the getScheduleSummary
method:
use omarchouman\LaraUtilX\Utilities\SchedulerUtil;
class MyController extends Controller
{
protected $schedulerUtil;
public function __construct(SchedulerUtil $schedulerUtil)
{
$this->schedulerUtil = $schedulerUtil;
}
public function getScheduleSummary()
{
$summary = $this->schedulerUtil->getScheduleSummary();
// Use the retrieved schedule summary
}
}
Check Overdue Tasks:
To check if any scheduled tasks are overdue, use the hasOverdueTasks
method:
use omarchouman\LaraUtilX\Utilities\SchedulerUtil;
class MyController extends Controller
{
protected $schedulerUtil;
public function __construct(SchedulerUtil $schedulerUtil)
{
$this->schedulerUtil = $schedulerUtil;
}
public function checkOverdueTasks()
{
$hasOverdueTasks = $this->schedulerUtil->hasOverdueTasks();
// Use the result to handle overdue tasks
}
}
The utility provides methods for retrieving a summary of scheduled tasks and checking if any tasks are overdue.
Success Result: A summary of scheduled tasks can be retrieved, including details such as command, expression, next run date, and status. Overdue tasks can also be detected using the provided method.
Error Result: If an error occurs during retrieval or detection of scheduled tasks, appropriate error handling mechanisms should be implemented based on application requirements.
You can publish this utility through the below command:
php artisan vendor:publish --tag=lara-util-x-scheduler
This utility enhances the management and monitoring of scheduled tasks in Laravel applications, providing insights into task execution and status.