Skip to content

Commit

Permalink
refactor entities
Browse files Browse the repository at this point in the history
  • Loading branch information
awasiak committed Oct 30, 2018
1 parent 98debdb commit cea29ca
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 143 deletions.
108 changes: 94 additions & 14 deletions src/SAREhub/Servitiom/Entity/Job/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,125 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace Servitiom\Entity\Job;
namespace SAREhub\Servitiom\Entity\Job;


use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embedded;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;

/**
* @Entity
* @Table(name="jobs")
**/
class Job
{
/**
* @Id
* @Column(type="integer", options={"unsigned": true})
* @GeneratedValue
* @var int
*/
private $id;

/**
* @var array
* @Column(type="string", length=65535)
* @var string
*/
private $payload;

/**
* @var int
* @ManyToOne(targetEntity="SAREhub\Servitiom\Entity\Job\Job")
* @JoinColumn(onDelete="CASCADE")
* @var Job
*/
private $priority;
private $parentJob;

/**
* @var string
* @Column(type="smallint", options={"unsigned": true})
* @var int
*/
private $queue;
private $maxRetries;

/**
* @var string
* @Column(type="integer", options={"unsigned": true})
* @var int
*/
private $createdAt;

/**
* @var int
* @Embedded(class = "SAREhub\Servitiom\Entity\Job\JobStatus")
*/
private $ttr;
private $status;

private $state;
public function getId(): int
{
return $this->id;
}

/**
* @var string
*/
private $internalJobId;
public function setId(int $id): Job
{
$this->id = $id;
return $this;
}

public function getPayload(): string
{
return $this->payload;
}

public function setPayload(string $payload): Job
{
$this->payload = $payload;
return $this;
}

public function getParentJob(): Job
{
return $this->parentJob;
}

public function setParentJob(Job $parentJob): Job
{
$this->parentJob = $parentJob;
return $this;
}

public function getMaxRetries(): int
{
return $this->maxRetries;
}

public function setMaxRetries(int $maxRetries): Job
{
$this->maxRetries = $maxRetries;
return $this;
}

public function getCreatedAt(): int
{
return $this->createdAt;
}

public function setCreatedAt(int $createdAt): Job
{
$this->createdAt = $createdAt;
return $this;
}

public function getStatus()
{
return $this->status;
}

public function setStatus($status)
{
$this->status = $status;
return $this;
}
}
19 changes: 19 additions & 0 deletions src/SAREhub/Servitiom/Entity/Job/JobStateType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace SAREhub\Servitiom\Entity\Job;


use MyCLabs\Enum\Enum;

class JobStateType extends Enum
{
const TODO = "todo";
const IN_PROGRESS = "in_progress";
const FAILED = "failed";
const DONE = "done";
}
43 changes: 43 additions & 0 deletions src/SAREhub/Servitiom/Entity/Job/JobStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace SAREhub\Servitiom\Entity\Job;


use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Embeddable;

/**
* @Embeddable
*/
class JobStatus
{

/**
* @Column(type="integer", options={"unsigned": true})
* @var int
*/
private $updatedAt;

/**
* @Column(type=JobState::class, length=255)
* @var JobStateType
*/
private $state;

/**
* @Column(type="smallint", options={"unsigned": true})
* @var int
*/
private $retries;

/**
* @Column(type="json", length=65535)
* @var array
*/
private $data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace SAREhub\Servitiom\Entity\Service;
namespace SAREhub\Servitiom\Entity\Service\Job;


use MyCLabs\Enum\Enum;
Expand Down
133 changes: 133 additions & 0 deletions src/SAREhub/Servitiom/Entity/Service/Job/ServiceJobTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

namespace SAREhub\Servitiom\Entity\Service\Job;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\UniqueConstraint;
use SAREhub\Servitiom\Entity\Service\ServiceVersion;

/**
* @Entity
* @Table(
* name="service_job_definitions",
* uniqueConstraints={@UniqueConstraint(name="unique_job_template",columns={"name", "scopeType", "serviceVersion"})}
* )
**/
class ServiceJobTemplate
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
* @var int
*/
private $id;

/**
* @Column(type="string", length=255)
* @var string
*/
private $name;

/**
* @Column(type=ServiceJobScopeType::class, length=255)
* @var ServiceJobScopeType
*/
private $scopeType;

/**
* @ManyToOne(targetEntity="SAREhub\Servitiom\Entity\Service\ServiceVersion")
* @JoinColumn(onDelete="CASCADE")
* @var ServiceVersion
*/
private $serviceVersion;

/**
* @Column(type="text", length=65535)
* @var string
*/
private $template;

/**
* @Column(type="integer", options={"unsigned": true})
* @var int
*/
private $createdAt;

public function getId(): int
{
return $this->id;
}

public function setId(int $id): ServiceJobTemplate
{
$this->id = $id;
return $this;
}

public function getName(): string
{
return $this->name;
}

public function setName(string $name): ServiceJobTemplate
{
$this->name = $name;
return $this;
}

public function getScopeType(): ServiceJobScopeType
{
return $this->scopeType;
}

public function setScopeType(ServiceJobScopeType $scopeType): ServiceJobTemplate
{
$this->scopeType = $scopeType;
return $this;
}

public function getServiceVersion(): ServiceVersion
{
return $this->serviceVersion;
}

public function setServiceVersion(ServiceVersion $serviceVersion): ServiceJobTemplate
{
$this->serviceVersion = $serviceVersion;
return $this;
}

public function getTemplate(): string
{
return $this->template;
}

public function setTemplate(string $template): ServiceJobTemplate
{
$this->template = $template;
return $this;
}

public function getCreatedAt(): int
{
return $this->createdAt;
}

public function setCreatedAt(int $createdAt): ServiceJobTemplate
{
$this->createdAt = $createdAt;
return $this;
}
}

0 comments on commit cea29ca

Please sign in to comment.