44 lines
985 B
PHP
44 lines
985 B
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Maintenance;
|
|
use App\Models\MaintenanceHistory;
|
|
use Cron\CronExpression;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class ScheduleNextMaintenance implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$maintenances = Maintenance::all();
|
|
foreach ($maintenances as $maintenance) {
|
|
$cron = new CronExpression($maintenance->schedule);
|
|
dump($cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s'));
|
|
|
|
|
|
$maintenance->history()->create([
|
|
'start_at' => $cron->getNextRunDate(null, 2)
|
|
]);
|
|
die();
|
|
}
|
|
}
|
|
}
|