-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from neighborhoods/KOJO-154-include-metadata-i…
…n-job-state-change-model KOJO-154 | Include metadata in job state change model
- Loading branch information
Showing
40 changed files
with
930 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Data\Job; | ||
|
||
use Neighborhoods\Kojo\Data; | ||
use Neighborhoods\Kojo\Data\JobInterface; | ||
|
||
class FromArrayBuilder implements FromArrayBuilderInterface | ||
{ | ||
/** @var array */ | ||
protected $record; | ||
|
||
public function build() : JobInterface | ||
{ | ||
$job = new Data\Job(); | ||
$record = $this->getRecord(); | ||
|
||
$job->setId($record['kojo_job_id']); | ||
$job->setAssignedState($record['assigned_state']); | ||
$job->setNextStateRequest($record['next_state_request']); | ||
$job->setTypeCode($record['type_code']); | ||
$job->setName($record['name']); | ||
$job->setPriority($record['priority']); | ||
$job->setImportance($record['importance']); | ||
$job->setWorkAtDateTime(new \DateTime($record['work_at_date_time'])); | ||
$job->setPreviousState($record['previous_state']); | ||
$job->setWorkerUri($record['worker_uri']); | ||
$job->setWorkerMethod($record['worker_method']); | ||
$job->setCanWorkInParallel($record['can_work_in_parallel']); | ||
$job->setLastTransitionInDateTime(new \DateTime($record['last_transition_date_time'])); | ||
$job->setLastTransitionInMicroTime( | ||
\DateTime::createFromFormat( | ||
'U.u', | ||
sprintf( | ||
'%s.%s', | ||
(int)($record['last_transition_micro_time'] / 1000000), | ||
$record['last_transition_micro_time'] % 1000000 | ||
) | ||
) | ||
); | ||
$job->setTimesWorked($record['times_worked']); | ||
$job->setTimesRetried($record['times_retried']); | ||
$job->setTimesHeld($record['times_held']); | ||
$job->setTimesCrashed($record['times_crashed']); | ||
$job->setTimesPanicked($record['times_panicked']); | ||
$job->setCreatedAtDateTime(new \DateTime($record['created_at_date_time'])); | ||
|
||
if (isset($record['completed_at_date_time'])) { | ||
$job->setCompletedAtDateTime(new \DateTime($record['completed_at_date_time'])); | ||
} | ||
if (isset($record['delete_after_date_time'])) { | ||
$job->setDeleteAfterDateTime(new \DateTime($record['delete_after_date_time'])); | ||
} | ||
|
||
return $job; | ||
} | ||
|
||
protected function getRecord() : array | ||
{ | ||
if ($this->record === null) { | ||
throw new \LogicException('FromArrayBuilder record has not been set.'); | ||
} | ||
|
||
return $this->record; | ||
} | ||
|
||
public function setRecord(array $record) : FromArrayBuilderInterface | ||
{ | ||
if ($this->record !== null) { | ||
throw new \LogicException('FromArrayBuilder record is already set.'); | ||
} | ||
|
||
$this->record = $record; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
neighborhoods.kojo.data.job.from_array_builder: | ||
class: Neighborhoods\Kojo\Data\Job\FromArrayBuilder | ||
shared: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Data\Job\FromArrayBuilder; | ||
|
||
use Neighborhoods\Kojo\Data\Job\FromArrayBuilderInterface; | ||
|
||
/** @codeCoverageIgnore */ | ||
trait AwareTrait | ||
{ | ||
protected $NeighborhoodsKojoDataJobFromArrayBuilder; | ||
|
||
public function setDataJobFromArrayBuilder(FromArrayBuilderInterface $dataJobFromArrayBuilder) : self | ||
{ | ||
if ($this->hasDataJobFromArrayBuilder()) { | ||
throw new \LogicException('NeighborhoodsKojoDataJobFromArrayBuilder is already set.'); | ||
} | ||
$this->NeighborhoodsKojoDataJobFromArrayBuilder = $dataJobFromArrayBuilder; | ||
|
||
return $this; | ||
} | ||
|
||
protected function getDataJobFromArrayBuilder() : FromArrayBuilderInterface | ||
{ | ||
if (!$this->hasDataJobFromArrayBuilder()) { | ||
throw new \LogicException('NeighborhoodsKojoDataJobFromArrayBuilder is not set.'); | ||
} | ||
|
||
return $this->NeighborhoodsKojoDataJobFromArrayBuilder; | ||
} | ||
|
||
protected function hasDataJobFromArrayBuilder() : bool | ||
{ | ||
return isset($this->NeighborhoodsKojoDataJobFromArrayBuilder); | ||
} | ||
|
||
protected function unsetDataJobFromArrayBuilder() : self | ||
{ | ||
if (!$this->hasDataJobFromArrayBuilder()) { | ||
throw new \LogicException('NeighborhoodsKojoDataJobFromArrayBuilder is not set.'); | ||
} | ||
unset($this->NeighborhoodsKojoDataJobFromArrayBuilder); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Data\Job\FromArrayBuilder; | ||
|
||
use Neighborhoods\Kojo\Data\Job\FromArrayBuilderInterface; | ||
|
||
/** @codeCoverageIgnore */ | ||
class Factory implements FactoryInterface | ||
{ | ||
use AwareTrait; | ||
|
||
public function create() : FromArrayBuilderInterface | ||
{ | ||
return clone $this->getDataJobFromArrayBuilder(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
neighborhoods.kojo.data.job.from_array_builder.factory: | ||
class: Neighborhoods\Kojo\Data\Job\FromArrayBuilder\Factory | ||
calls: | ||
- [setDataJobFromArrayBuilder, ['@neighborhoods.kojo.data.job.from_array_builder']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Data\Job\FromArrayBuilder\Factory; | ||
|
||
use Neighborhoods\Kojo\Data\Job\FromArrayBuilder\FactoryInterface; | ||
|
||
/** @codeCoverageIgnore */ | ||
trait AwareTrait | ||
{ | ||
protected $NeighborhoodsKojoDataJobFromArrayBuilderFactory; | ||
|
||
public function setDataJobFromArrayBuilderFactory(FactoryInterface $dataJobFromArrayBuilderFactory) : self | ||
{ | ||
if ($this->hasDataJobFromArrayBuilderFactory()) { | ||
throw new \LogicException('NeighborhoodsKojoDataJobFromArrayBuilderFactory is already set.'); | ||
} | ||
$this->NeighborhoodsKojoDataJobFromArrayBuilderFactory = $dataJobFromArrayBuilderFactory; | ||
|
||
return $this; | ||
} | ||
|
||
protected function getDataJobFromArrayBuilderFactory() : FactoryInterface | ||
{ | ||
if (!$this->hasDataJobFromArrayBuilderFactory()) { | ||
throw new \LogicException('NeighborhoodsKojoDataJobFromArrayBuilderFactory is not set.'); | ||
} | ||
|
||
return $this->NeighborhoodsKojoDataJobFromArrayBuilderFactory; | ||
} | ||
|
||
protected function hasDataJobFromArrayBuilderFactory() : bool | ||
{ | ||
return isset($this->NeighborhoodsKojoDataJobFromArrayBuilderFactory); | ||
} | ||
|
||
protected function unsetDataJobFromArrayBuilderFactory() : self | ||
{ | ||
if (!$this->hasDataJobFromArrayBuilderFactory()) { | ||
throw new \LogicException('NeighborhoodsKojoDataJobFromArrayBuilderFactory is not set.'); | ||
} | ||
unset($this->NeighborhoodsKojoDataJobFromArrayBuilderFactory); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Data\Job\FromArrayBuilder; | ||
|
||
use Neighborhoods\Kojo\Data\Job\FromArrayBuilderInterface; | ||
|
||
/** @codeCoverageIgnore */ | ||
interface FactoryInterface | ||
{ | ||
public function create() : FromArrayBuilderInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neighborhoods\Kojo\Data\Job; | ||
|
||
use Neighborhoods\Kojo\Data\JobInterface; | ||
|
||
interface FromArrayBuilderInterface | ||
{ | ||
public function build() : JobInterface; | ||
|
||
public function setRecord(array $record) : FromArrayBuilderInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.