diff --git a/src/Data/Job/FromArrayBuilder.php b/src/Data/Job/FromArrayBuilder.php new file mode 100644 index 00000000..4620bf07 --- /dev/null +++ b/src/Data/Job/FromArrayBuilder.php @@ -0,0 +1,78 @@ +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; + } +} diff --git a/src/Data/Job/FromArrayBuilder.yml b/src/Data/Job/FromArrayBuilder.yml new file mode 100644 index 00000000..a7b8f7b7 --- /dev/null +++ b/src/Data/Job/FromArrayBuilder.yml @@ -0,0 +1,4 @@ +services: + neighborhoods.kojo.data.job.from_array_builder: + class: Neighborhoods\Kojo\Data\Job\FromArrayBuilder + shared: false diff --git a/src/Data/Job/FromArrayBuilder/AwareTrait.php b/src/Data/Job/FromArrayBuilder/AwareTrait.php new file mode 100644 index 00000000..221bde9d --- /dev/null +++ b/src/Data/Job/FromArrayBuilder/AwareTrait.php @@ -0,0 +1,46 @@ +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; + } +} diff --git a/src/Data/Job/FromArrayBuilder/Factory.php b/src/Data/Job/FromArrayBuilder/Factory.php new file mode 100644 index 00000000..a647958a --- /dev/null +++ b/src/Data/Job/FromArrayBuilder/Factory.php @@ -0,0 +1,17 @@ +getDataJobFromArrayBuilder(); + } +} diff --git a/src/Data/Job/FromArrayBuilder/Factory.yml b/src/Data/Job/FromArrayBuilder/Factory.yml new file mode 100644 index 00000000..93fe6add --- /dev/null +++ b/src/Data/Job/FromArrayBuilder/Factory.yml @@ -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']] diff --git a/src/Data/Job/FromArrayBuilder/Factory/AwareTrait.php b/src/Data/Job/FromArrayBuilder/Factory/AwareTrait.php new file mode 100644 index 00000000..ee4f7566 --- /dev/null +++ b/src/Data/Job/FromArrayBuilder/Factory/AwareTrait.php @@ -0,0 +1,46 @@ +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; + } +} diff --git a/src/Data/Job/FromArrayBuilder/FactoryInterface.php b/src/Data/Job/FromArrayBuilder/FactoryInterface.php new file mode 100644 index 00000000..07704011 --- /dev/null +++ b/src/Data/Job/FromArrayBuilder/FactoryInterface.php @@ -0,0 +1,12 @@ +getJobStateChangeFactory()->create(); + $jobStateChange = $this->getJobStateChangeFactory()->create(); $record = $this->getRecord(); - $JobStateChange->setId((int)$record[JobStateChangeInterface::PROP_ID]); - $JobStateChange->setData( + $jobStateChange->setId((int)$record[JobStateChangeInterface::PROP_ID]); + $jobStateChange->setData( $this ->getJobStateChangeDataBuilderFactory() ->create() @@ -27,7 +27,7 @@ public function build() : JobStateChangeInterface ->build() ); - return $JobStateChange; + return $jobStateChange; } protected function getRecord() : array diff --git a/src/JobStateChange/Data.php b/src/JobStateChange/Data.php index 519e20cd..12cdd020 100644 --- a/src/JobStateChange/Data.php +++ b/src/JobStateChange/Data.php @@ -3,6 +3,8 @@ namespace Neighborhoods\Kojo\JobStateChange; +use Neighborhoods\Kojo\Process\Pool\Logger\Message; + class Data implements DataInterface { /** @var string */ @@ -11,8 +13,8 @@ class Data implements DataInterface protected $new_state; /** @var \DateTimeInterface */ protected $timestamp; - /** @var ? */ - // protected $metadata; + /** @var Message\MetadataInterface */ + protected $metadata; public function getOldState() : string { @@ -64,4 +66,21 @@ public function setTimestamp(\DateTimeInterface $timestamp) : DataInterface $this->timestamp = $timestamp; return $this; } + + public function getMetadata() : Message\MetadataInterface + { + if ($this->metadata === null) { + throw new \LogicException('Data metadata has not been set.'); + } + return $this->metadata; + } + + public function setMetadata(Message\MetadataInterface $metadata) : DataInterface + { + if ($this->metadata !== null) { + throw new \LogicException('Data metadata is already set.'); + } + $this->metadata = $metadata; + return $this; + } } diff --git a/src/JobStateChange/Data/Builder.php b/src/JobStateChange/Data/Builder.php index abd4c8b7..cf8b73fd 100644 --- a/src/JobStateChange/Data/Builder.php +++ b/src/JobStateChange/Data/Builder.php @@ -4,9 +4,11 @@ namespace Neighborhoods\Kojo\JobStateChange\Data; use Neighborhoods\Kojo\JobStateChange\DataInterface; +use Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata; class Builder implements BuilderInterface { + use Metadata\FromArrayBuilder\Factory\AwareTrait; use Factory\AwareTrait; /** @var array */ protected $record; @@ -20,6 +22,14 @@ public function build() : DataInterface $data->setNewState($record[DataInterface::PROP_NEW_STATE]); $data->setTimestamp(new \DateTimeImmutable($record[DataInterface::PROP_TIMESTAMP])); + $metadata = $this + ->getProcessPoolLoggerMessageMetadataFromArrayBuilderFactory() + ->create() + ->setRecord($record[DataInterface::PROP_METADATA]) + ->build(); + + $data->setMetadata($metadata); + return $data; } diff --git a/src/JobStateChange/Data/Builder.yml b/src/JobStateChange/Data/Builder.yml index 971a0610..0bdb1da9 100644 --- a/src/JobStateChange/Data/Builder.yml +++ b/src/JobStateChange/Data/Builder.yml @@ -5,6 +5,7 @@ services: shared: false calls: - [setJobStateChangeDataFactory, ['@job_state_change.data.factory']] + - [setProcessPoolLoggerMessageMetadataFromArrayBuilderFactory, ['@neighborhoods.kojo.process.pool.logger.message.metadata.from_array_builder.factory']] job_state_change.data.builder: alias: neighborhoods.kojo.job_state_change.data.builder public: false diff --git a/src/JobStateChange/DataInterface.php b/src/JobStateChange/DataInterface.php index ee24b8ce..2a2f759f 100644 --- a/src/JobStateChange/DataInterface.php +++ b/src/JobStateChange/DataInterface.php @@ -3,12 +3,14 @@ namespace Neighborhoods\Kojo\JobStateChange; +use Neighborhoods\Kojo\Process\Pool\Logger\Message; + interface DataInterface { public const PROP_OLD_STATE = 'old_state'; public const PROP_NEW_STATE = 'new_state'; public const PROP_TIMESTAMP = 'timestamp'; - // public const PROP_METADATA = 'metadata'; + public const PROP_METADATA = 'metadata'; public function getOldState() : string; public function setOldState(string $old_state) : DataInterface; @@ -18,4 +20,7 @@ public function setNewState(string $new_state) : DataInterface; public function getTimestamp() : \DateTimeInterface; public function setTimestamp(\DateTimeInterface $timestamp) : DataInterface; + + public function getMetadata() : Message\MetadataInterface; + public function setMetadata(Message\MetadataInterface $metadata) : DataInterface; } diff --git a/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder.php b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder.php new file mode 100644 index 00000000..be77ab1e --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder.php @@ -0,0 +1,67 @@ +getProcessPoolLoggerMessageMetadataFactory()->create(); + $record = $this->getRecord(); + + $serializableProcess = $this + ->getProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory() + ->create() + ->setRecord($record['process']) + ->build(); + $metadata->setProcess($serializableProcess); + + $job = $this + ->getDataJobFromArrayBuilderFactory() + ->create() + ->setRecord($record['job']) + ->build(); + $metadata->setJob($job); + + $host = $this + ->getProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory() + ->create() + ->setRecord($record['host']) + ->build(); + $metadata->setHost($host); + + return $metadata; + } + + 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; + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder.yml b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder.yml new file mode 100644 index 00000000..6582efb1 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder.yml @@ -0,0 +1,9 @@ +services: + neighborhoods.kojo.process.pool.logger.message.metadata.from_array_builder: + class: Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata\FromArrayBuilder + shared: false + calls: + - [setProcessPoolLoggerMessageMetadataFactory, ['@neighborhoods.kojo.process.pool.logger.message.metadata.factory']] + - [setProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory, ['@neighborhoods.kojo.process.pool.logger.message.serializable_process.from_array_builder.factory']] + - [setDataJobFromArrayBuilderFactory, ['@neighborhoods.kojo.data.job.from_array_builder.factory']] + - [setProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory, ['@neighborhoods.kojo.process.pool.logger.message.metadata.host.from_array_builder.factory']] diff --git a/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/AwareTrait.php b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/AwareTrait.php new file mode 100644 index 00000000..b2d03377 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/AwareTrait.php @@ -0,0 +1,46 @@ +hasProcessPoolLoggerMessageMetadataFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilder is already set.'); + } + $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilder = $processPoolLoggerMessageMetadataFromArrayBuilder; + + return $this; + } + + protected function getProcessPoolLoggerMessageMetadataFromArrayBuilder() : FromArrayBuilderInterface + { + if (!$this->hasProcessPoolLoggerMessageMetadataFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilder is not set.'); + } + + return $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilder; + } + + protected function hasProcessPoolLoggerMessageMetadataFromArrayBuilder() : bool + { + return isset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilder); + } + + protected function unsetProcessPoolLoggerMessageMetadataFromArrayBuilder() : self + { + if (!$this->hasProcessPoolLoggerMessageMetadataFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilder is not set.'); + } + unset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilder); + + return $this; + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory.php b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory.php new file mode 100644 index 00000000..4044462a --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory.php @@ -0,0 +1,17 @@ +getProcessPoolLoggerMessageMetadataFromArrayBuilder(); + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory.yml b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory.yml new file mode 100644 index 00000000..ac5f8927 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory.yml @@ -0,0 +1,5 @@ +services: + neighborhoods.kojo.process.pool.logger.message.metadata.from_array_builder.factory: + class: Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata\FromArrayBuilder\Factory + calls: + - [setProcessPoolLoggerMessageMetadataFromArrayBuilder, ['@neighborhoods.kojo.process.pool.logger.message.metadata.from_array_builder']] diff --git a/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory/AwareTrait.php b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory/AwareTrait.php new file mode 100644 index 00000000..1da2855c --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/Factory/AwareTrait.php @@ -0,0 +1,46 @@ +hasProcessPoolLoggerMessageMetadataFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilderFactory is already set.'); + } + $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilderFactory = $processPoolLoggerMessageMetadataFromArrayBuilderFactory; + + return $this; + } + + protected function getProcessPoolLoggerMessageMetadataFromArrayBuilderFactory() : FactoryInterface + { + if (!$this->hasProcessPoolLoggerMessageMetadataFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilderFactory is not set.'); + } + + return $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilderFactory; + } + + protected function hasProcessPoolLoggerMessageMetadataFromArrayBuilderFactory() : bool + { + return isset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilderFactory); + } + + protected function unsetProcessPoolLoggerMessageMetadataFromArrayBuilderFactory() : self + { + if (!$this->hasProcessPoolLoggerMessageMetadataFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilderFactory is not set.'); + } + unset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataFromArrayBuilderFactory); + + return $this; + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/FactoryInterface.php b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/FactoryInterface.php new file mode 100644 index 00000000..164c2f5a --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/FromArrayBuilder/FactoryInterface.php @@ -0,0 +1,12 @@ +host_name !== null) { + throw new \LogicException('Host host_name is already set.'); + } + $this->host_name = $host_name; + return $this; + } + public function getLoadAverage() : float { return (float)current(sys_getloadavg()); } + public function setLoadAverage(float $load_average) : HostInterface + { + if ($this->load_average !== null) { + throw new \LogicException('Host load_average is already set.'); + } + $this->load_average = $load_average; + return $this; + } + public function jsonSerialize() { $data = get_object_vars($this); - $data[self::KEY_HOST_NAME] = $this->getHostName(); - $data[self::KEY_LOAD_AVERAGE] = $this->getLoadAverage(); + + if (!isset($data[self::KEY_HOST_NAME])) { + $data[self::KEY_HOST_NAME] = $this->getHostName(); + } + if (!isset($data[self::KEY_LOAD_AVERAGE])) { + $data[self::KEY_LOAD_AVERAGE] = $this->getLoadAverage(); + } return $data; } diff --git a/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder.php b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder.php new file mode 100644 index 00000000..97085456 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder.php @@ -0,0 +1,43 @@ +getRecord(); + + $host->setHostName($record['host_name']); + $host->setLoadAverage($record['load_average']); + + return $host; + } + + 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; + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder.yml b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder.yml new file mode 100644 index 00000000..0fdc3a1d --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder.yml @@ -0,0 +1,4 @@ +services: + neighborhoods.kojo.process.pool.logger.message.metadata.host.from_array_builder: + class: Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata\Host\FromArrayBuilder + shared: false diff --git a/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/AwareTrait.php b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/AwareTrait.php new file mode 100644 index 00000000..fd4ff7c9 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/AwareTrait.php @@ -0,0 +1,46 @@ +hasProcessPoolLoggerMessageMetadataHostFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilder is already set.'); + } + $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilder = $processPoolLoggerMessageMetadataHostFromArrayBuilder; + + return $this; + } + + protected function getProcessPoolLoggerMessageMetadataHostFromArrayBuilder() : FromArrayBuilderInterface + { + if (!$this->hasProcessPoolLoggerMessageMetadataHostFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilder is not set.'); + } + + return $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilder; + } + + protected function hasProcessPoolLoggerMessageMetadataHostFromArrayBuilder() : bool + { + return isset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilder); + } + + protected function unsetProcessPoolLoggerMessageMetadataHostFromArrayBuilder() : self + { + if (!$this->hasProcessPoolLoggerMessageMetadataHostFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilder is not set.'); + } + unset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilder); + + return $this; + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory.php b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory.php new file mode 100644 index 00000000..20070171 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory.php @@ -0,0 +1,17 @@ +getProcessPoolLoggerMessageMetadataHostFromArrayBuilder(); + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory.yml b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory.yml new file mode 100644 index 00000000..743b31e5 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory.yml @@ -0,0 +1,5 @@ +services: + neighborhoods.kojo.process.pool.logger.message.metadata.host.from_array_builder.factory: + class: Neighborhoods\Kojo\Process\Pool\Logger\Message\Metadata\Host\FromArrayBuilder\Factory + calls: + - [setProcessPoolLoggerMessageMetadataHostFromArrayBuilder, ['@neighborhoods.kojo.process.pool.logger.message.metadata.host.from_array_builder']] diff --git a/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory/AwareTrait.php b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory/AwareTrait.php new file mode 100644 index 00000000..4cd9aa00 --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/Factory/AwareTrait.php @@ -0,0 +1,46 @@ +hasProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory is already set.'); + } + $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory = $processPoolLoggerMessageMetadataHostFromArrayBuilderFactory; + + return $this; + } + + protected function getProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory() : FactoryInterface + { + if (!$this->hasProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory is not set.'); + } + + return $this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory; + } + + protected function hasProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory() : bool + { + return isset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory); + } + + protected function unsetProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory() : self + { + if (!$this->hasProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory is not set.'); + } + unset($this->NeighborhoodsKojoProcessPoolLoggerMessageMetadataHostFromArrayBuilderFactory); + + return $this; + } +} diff --git a/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/FactoryInterface.php b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/FactoryInterface.php new file mode 100644 index 00000000..aad6b22e --- /dev/null +++ b/src/Process/Pool/Logger/Message/Metadata/Host/FromArrayBuilder/FactoryInterface.php @@ -0,0 +1,12 @@ +memory_usage_bytes !== null) { + throw new \LogicException('SerializableProcess memory_usage_bytes is already set.'); + } + $this->memory_usage_bytes = $memory_usage_bytes; + return $this; } public function getMemoryPeakUsageBytes() : int @@ -136,17 +145,43 @@ public function getMemoryPeakUsageBytes() : int return memory_get_peak_usage(); } + public function setMemoryPeakUsageBytes(int $memory_peak_usage_bytes) : SerializableProcessInterface + { + if ($this->memory_peak_usage_bytes !== null) { + throw new \LogicException('SerializableProcess memory_peak_usage_bytes is already set.'); + } + $this->memory_peak_usage_bytes = $memory_peak_usage_bytes; + return $this; + } + public function getMemoryLimitBytes() : int { return $this->dataUnitToBytes(ini_get('memory_limit')); } + public function setMemoryLimitBytes(int $memory_limit_bytes) : SerializableProcessInterface + { + if ($this->memory_limit_bytes !== null) { + throw new \LogicException('SerializableProcess memory_limit_bytes is already set.'); + } + $this->memory_limit_bytes = $memory_limit_bytes; + return $this; + } + public function jsonSerialize() { $data = get_object_vars($this); - $data[self::KEY_MEMORY_USAGE_BYTES]= $this->getMemoryUsageBytes(); - $data[self::KEY_MEMORY_PEAK_USAGE_BYTES]= $this->getMemoryPeakUsageBytes(); - $data[self::KEY_MEMORY_LIMIT_BYTES]= $this->getMemoryLimitBytes(); + + if (!isset($data[self::KEY_MEMORY_USAGE_BYTES])) { + $data[self::KEY_MEMORY_USAGE_BYTES] = $this->getMemoryUsageBytes(); + } + if (!isset($data[self::KEY_MEMORY_PEAK_USAGE_BYTES])) { + $data[self::KEY_MEMORY_PEAK_USAGE_BYTES] = $this->getMemoryPeakUsageBytes(); + } + if (!isset($data[self::KEY_MEMORY_LIMIT_BYTES])) { + $data[self::KEY_MEMORY_LIMIT_BYTES] = $this->getMemoryLimitBytes(); + } + return $data; } diff --git a/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder.php b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder.php new file mode 100644 index 00000000..55fee3cc --- /dev/null +++ b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder.php @@ -0,0 +1,51 @@ +getProcessPoolLoggerMessageSerializableProcessFactory()->create(); + $record = $this->getRecord(); + + $serializableProcess->setProcessId($record['process_id']); + $serializableProcess->setParentProcessId($record['parent_process_id']); + $serializableProcess->setPath($record['path']); + $serializableProcess->setUuid($record['uuid']); + $serializableProcess->setTypeCode($record['type_code']); + $serializableProcess->setMemoryUsageBytes($record['memory_usage_bytes']); + $serializableProcess->setMemoryPeakUsageBytes($record['memory_peak_usage_bytes']); + $serializableProcess->setMemoryLimitBytes($record['memory_limit_bytes']); + + return $serializableProcess; + } + + 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; + } +} diff --git a/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder.yml b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder.yml new file mode 100644 index 00000000..cecb97a4 --- /dev/null +++ b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder.yml @@ -0,0 +1,6 @@ +services: + neighborhoods.kojo.process.pool.logger.message.serializable_process.from_array_builder: + class: Neighborhoods\Kojo\Process\Pool\Logger\Message\SerializableProcess\FromArrayBuilder + shared: false + calls: + - [setProcessPoolLoggerMessageSerializableProcessFactory, ['@neighborhoods.kojo.process.pool.logger.message.serializable_process.factory']] diff --git a/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/AwareTrait.php b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/AwareTrait.php new file mode 100644 index 00000000..5f9c89ba --- /dev/null +++ b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/AwareTrait.php @@ -0,0 +1,46 @@ +hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilder is already set.'); + } + $this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilder = $processPoolLoggerMessageSerializableProcessFromArrayBuilder; + + return $this; + } + + protected function getProcessPoolLoggerMessageSerializableProcessFromArrayBuilder() : FromArrayBuilderInterface + { + if (!$this->hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilder is not set.'); + } + + return $this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilder; + } + + protected function hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilder() : bool + { + return isset($this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilder); + } + + protected function unsetProcessPoolLoggerMessageSerializableProcessFromArrayBuilder() : self + { + if (!$this->hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilder()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilder is not set.'); + } + unset($this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilder); + + return $this; + } +} diff --git a/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory.php b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory.php new file mode 100644 index 00000000..a74754e2 --- /dev/null +++ b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory.php @@ -0,0 +1,17 @@ +getProcessPoolLoggerMessageSerializableProcessFromArrayBuilder(); + } +} diff --git a/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory.yml b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory.yml new file mode 100644 index 00000000..8f32e5de --- /dev/null +++ b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory.yml @@ -0,0 +1,5 @@ +services: + neighborhoods.kojo.process.pool.logger.message.serializable_process.from_array_builder.factory: + class: Neighborhoods\Kojo\Process\Pool\Logger\Message\SerializableProcess\FromArrayBuilder\Factory + calls: + - [setProcessPoolLoggerMessageSerializableProcessFromArrayBuilder, ['@neighborhoods.kojo.process.pool.logger.message.serializable_process.from_array_builder']] diff --git a/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory/AwareTrait.php b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory/AwareTrait.php new file mode 100644 index 00000000..39f71862 --- /dev/null +++ b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/Factory/AwareTrait.php @@ -0,0 +1,46 @@ +hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory is already set.'); + } + $this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory = $processPoolLoggerMessageSerializableProcessFromArrayBuilderFactory; + + return $this; + } + + protected function getProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory() : FactoryInterface + { + if (!$this->hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory is not set.'); + } + + return $this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory; + } + + protected function hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory() : bool + { + return isset($this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory); + } + + protected function unsetProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory() : self + { + if (!$this->hasProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory()) { + throw new \LogicException('NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory is not set.'); + } + unset($this->NeighborhoodsKojoProcessPoolLoggerMessageSerializableProcessFromArrayBuilderFactory); + + return $this; + } +} diff --git a/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/FactoryInterface.php b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/FactoryInterface.php new file mode 100644 index 00000000..dcebd369 --- /dev/null +++ b/src/Process/Pool/Logger/Message/SerializableProcess/FromArrayBuilder/FactoryInterface.php @@ -0,0 +1,12 @@ +