This commit is contained in:
Dennis Eichhorn 2018-08-02 18:30:20 +02:00
parent 6cc520a579
commit 16e0462a89
5 changed files with 43 additions and 44 deletions

View File

@ -25,21 +25,6 @@ namespace phpOMS\Utils\TaskSchedule;
*/ */
class Cron extends SchedulerAbstract class Cron extends SchedulerAbstract
{ {
/**
* Normalize run result for easier parsing
*
* @param string $raw Raw command output
*
* @return string Normalized string for parsing
*
* @since 1.0.0
*/
private function normalize(string $raw) : string
{
return \str_replace("\r\n", "\n", $raw);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace phpOMS\Utils\TaskSchedule; namespace phpOMS\Utils\TaskSchedule;
use phpOMS\Validation\Base\DateTime;
/** /**
* CronJob class. * CronJob class.
* *
@ -29,10 +31,22 @@ class CronJob extends TaskAbstract
*/ */
public static function createWith(array $jobData) : TaskAbstract public static function createWith(array $jobData) : TaskAbstract
{ {
$job = new self($jobData[5], ''); $job = new self($jobData[1], '');
$job->setRun($jobData[5]); $job->setRun($jobData[8]);
$job->setStatus($jobData[3]);
return $job; if (DateTime::isValid($jobData[2])) {
$job->setNextRunTime(new \DateTime($jobData[2]));
}
if (DateTime::isValid($jobData[5])) {
$job->setLastRuntime(new \DateTime($jobData[5]));
}
$job->setComment($jobData[10]);
$job->addResult($jobData[6]);
return $job;
} }
} }

View File

@ -31,22 +31,22 @@ class Schedule extends TaskAbstract
*/ */
public static function createWith(array $jobData) : TaskAbstract public static function createWith(array $jobData) : TaskAbstract
{ {
$job = new self($jobData[1], ''); $job = new self($jobData[1], '');
$job->setRun($jobData[8]); $job->setRun($jobData[8]);
$job->setStatus($jobData[3]); $job->setStatus($jobData[3]);
if (DateTime::isValid($jobData[2])) { if (DateTime::isValid($jobData[2])) {
$job->setNextRunTime(new \DateTime($jobData[2])); $job->setNextRunTime(new \DateTime($jobData[2]));
} }
if (DateTime::isValid($jobData[5])) { if (DateTime::isValid($jobData[5])) {
$job->setLastRuntime(new \DateTime($jobData[5])); $job->setLastRuntime(new \DateTime($jobData[5]));
} }
$job->setComment($jobData[10]); $job->setComment($jobData[10]);
$job->addResult($jobData[6]); $job->addResult($jobData[6]);
return $job; return $job;
} }
} }

View File

@ -182,6 +182,20 @@ abstract class SchedulerAbstract
$this->run($task->getCommand()); $this->run($task->getCommand());
} }
/**
* Normalize run result for easier parsing
*
* @param string $raw Raw command output
*
* @return string Normalized string for parsing
*
* @since 1.0.0
*/
protected function normalize(string $raw) : string
{
return \str_replace("\r\n", "\n", $raw);
}
/** /**
* Get all jobs/tasks by name * Get all jobs/tasks by name
* *

View File

@ -25,20 +25,6 @@ namespace phpOMS\Utils\TaskSchedule;
*/ */
class TaskScheduler extends SchedulerAbstract class TaskScheduler extends SchedulerAbstract
{ {
/**
* Normalize run result for easier parsing
*
* @param string $raw Raw command output
*
* @return string Normalized string for parsing
*
* @since 1.0.0
*/
private function normalize(string $raw) : string
{
return \str_replace("\r\n", "\n", $raw);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */