Begin adding schedule processing jobs.
This commit is contained in:
parent
c0d7e02481
commit
c5f2dfd6f6
16 changed files with 626 additions and 49 deletions
|
@ -24,6 +24,7 @@
|
|||
|
||||
namespace Pterodactyl\Services\Schedules;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
@ -83,6 +84,7 @@ class ScheduleCreationService
|
|||
|
||||
$server = ($server instanceof Server) ? $server->id : $server;
|
||||
$data['server_id'] = $server;
|
||||
$data['next_run_at'] = $this->getCronTimestamp($data);
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
$schedule = $this->repository->create($data);
|
||||
|
@ -103,4 +105,22 @@ class ScheduleCreationService
|
|||
|
||||
return $schedule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a DateTime object after parsing the cron data provided.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \DateTime
|
||||
*/
|
||||
private function getCronTimestamp(array $data)
|
||||
{
|
||||
$formattedCron = sprintf('%s %s %s * %s *',
|
||||
array_get($data, 'cron_minute', '*'),
|
||||
array_get($data, 'cron_hour', '*'),
|
||||
array_get($data, 'cron_day_of_month', '*'),
|
||||
array_get($data, 'cron_day_of_week', '*')
|
||||
);
|
||||
|
||||
return CronExpression::factory($formattedCron)->getNextRunDate();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue