-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b178ad
commit c99360c
Showing
12 changed files
with
522 additions
and
0 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ jobs: | |
- aws-tool-kit | ||
- console | ||
- core | ||
- cron-job | ||
- doctrine-extra | ||
- entity-migrator | ||
- fixer | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/vendor/ | ||
/.idea/ | ||
composer.lock | ||
|
||
###> phpunit/phpunit ### | ||
/phpunit.xml | ||
.phpunit.result.cache | ||
###< phpunit/phpunit ### |
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,169 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Component\CronJob\Entity; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ | ||
ORM\Entity, | ||
ORM\Table(name: 'cron_job__cron_job'), | ||
] | ||
class CronJob implements \Stringable | ||
{ | ||
#[ | ||
ORM\Id, | ||
ORM\GeneratedValue, | ||
ORM\Column(name: 'id', type: 'int'), | ||
] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column(name: 'name', type: 'string', length: 255, unique: true, nullable: false)] | ||
private ?string $name = null; | ||
|
||
#[ORM\Column(name: 'active', type: 'boolean', options: ['default' => false])] | ||
private bool $active = false; | ||
|
||
#[ORM\Column(name: 'command', type: 'string', length: 255, nullable: false)] | ||
private ?string $command = null; | ||
|
||
#[ORM\Column(name: 'schedule', type: 'string', length: 255, nullable: true)] | ||
private ?string $schedule = null; | ||
|
||
#[ORM\Column(name: 'ttl', type: 'int', nullable: false, options: ['default' => 0])] | ||
private int $ttl = 0; | ||
|
||
#[ORM\Column(name: 'priority', type: 'int', nullable: true)] | ||
private ?int $priority = null; | ||
|
||
/** | ||
* @var Collection<CronJobExecution> | ||
*/ | ||
#[ | ||
ORM\OneToMany( | ||
mappedBy: 'cronJob', | ||
targetEntity: CronJobExecution::class, | ||
cascade: ['persist'], | ||
orphanRemoval: true, | ||
) | ||
] | ||
private Collection $executions; | ||
|
||
public function __construct() | ||
{ | ||
$this->executions = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(?string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function isActive(): bool | ||
{ | ||
return $this->active; | ||
} | ||
|
||
public function setActive(bool $active): self | ||
{ | ||
$this->active = $active; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCommand(): ?string | ||
{ | ||
return $this->command; | ||
} | ||
|
||
public function setCommand(?string $command): self | ||
{ | ||
$this->command = $command; | ||
|
||
return $this; | ||
} | ||
|
||
public function getSchedule(): ?string | ||
{ | ||
return $this->schedule; | ||
} | ||
|
||
public function setSchedule(?string $schedule): self | ||
{ | ||
$this->schedule = $schedule; | ||
|
||
return $this; | ||
} | ||
|
||
public function getTtl(): int | ||
{ | ||
return $this->ttl; | ||
} | ||
|
||
public function setTtl(int $ttl): self | ||
{ | ||
$this->ttl = $ttl; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPriority(): ?int | ||
{ | ||
return $this->priority; | ||
} | ||
|
||
public function setPriority(?int $priority): self | ||
{ | ||
$this->priority = $priority; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection<CronJobExecution> | ||
*/ | ||
public function getExecutions(): Collection | ||
{ | ||
return $this->executions; | ||
} | ||
|
||
public function addExecution(CronJobExecution $execution): self | ||
{ | ||
if (!$this->executions->contains($execution)) { | ||
$this->executions->add($execution); | ||
$execution->setCronJob($this); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeExecution(CronJobExecution $execution): self | ||
{ | ||
if ($this->executions->contains($execution)) { | ||
$this->executions->removeElement($execution); | ||
$execution->setCronJob(null); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->name; | ||
} | ||
} |
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,157 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Component\CronJob\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ | ||
ORM\Entity, | ||
ORM\Table(name: 'cron_job__cron_job_execution'), | ||
] | ||
class CronJobExecution | ||
{ | ||
#[ | ||
ORM\Id, | ||
ORM\GeneratedValue, | ||
ORM\Column(name: 'id', type: 'integer'), | ||
] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column(name: 'requested_at', type: 'datetime_immutable', nullable: false)] | ||
private ?\DateTimeImmutable $requestedAt = null; | ||
|
||
#[ORM\Column(name: 'force', type: 'boolean', options: ['default' => false])] | ||
private bool $force = false; | ||
|
||
#[ORM\Column(name: 'execution_started_at', type: 'datetime_immutable', nullable: true)] | ||
private ?\DateTimeImmutable $executionStartedAt = null; | ||
|
||
#[ORM\Column(name: 'execution_ended_at', type: 'datetime_immutable', nullable: true)] | ||
private ?\DateTimeImmutable $executionEndedAt = null; | ||
|
||
#[ORM\Column(name: 'execution_delay', type: 'int', nullable: true)] | ||
private ?int $executionDelay = null; | ||
|
||
#[ORM\Column(name: 'exit_code', type: 'int', nullable: true)] | ||
private ?int $exitCode = null; | ||
|
||
#[ORM\Column(name: 'error', type: 'json', nullable: true)] | ||
private ?array $error = null; | ||
|
||
#[ | ||
ORM\ManyToOne( | ||
targetEntity: CronJob::class, | ||
inversedBy: 'executions', | ||
), | ||
ORM\JoinColumn( | ||
name: 'cron_job_id', | ||
referencedColumnName: 'id', | ||
nullable: false, | ||
onDelete: 'CASCADE', | ||
) | ||
] | ||
private ?CronJob $cronJob = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getRequestedAt(): ?\DateTimeImmutable | ||
{ | ||
return $this->requestedAt; | ||
} | ||
|
||
public function setRequestedAt(?\DateTimeImmutable $requestedAt): self | ||
{ | ||
$this->requestedAt = $requestedAt; | ||
|
||
return $this; | ||
} | ||
|
||
public function isForce(): bool | ||
{ | ||
return $this->force; | ||
} | ||
|
||
public function setForce(bool $force): self | ||
{ | ||
$this->force = $force; | ||
|
||
return $this; | ||
} | ||
|
||
public function getExecutionStartedAt(): ?\DateTimeImmutable | ||
{ | ||
return $this->executionStartedAt; | ||
} | ||
|
||
public function setExecutionStartedAt(?\DateTimeImmutable $executionStartedAt): self | ||
{ | ||
$this->executionStartedAt = $executionStartedAt; | ||
|
||
return $this; | ||
} | ||
|
||
public function getExecutionEndedAt(): ?\DateTimeImmutable | ||
{ | ||
return $this->executionEndedAt; | ||
} | ||
|
||
public function setExecutionEndedAt(?\DateTimeImmutable $executionEndedAt): self | ||
{ | ||
$this->executionEndedAt = $executionEndedAt; | ||
|
||
return $this; | ||
} | ||
|
||
public function getExecutionDelay(): ?int | ||
{ | ||
return $this->executionDelay; | ||
} | ||
|
||
public function setExecutionDelay(?int $executionDelay): self | ||
{ | ||
$this->executionDelay = $executionDelay; | ||
|
||
return $this; | ||
} | ||
|
||
public function getExitCode(): ?int | ||
{ | ||
return $this->exitCode; | ||
} | ||
|
||
public function setExitCode(?int $exitCode): self | ||
{ | ||
$this->exitCode = $exitCode; | ||
|
||
return $this; | ||
} | ||
|
||
public function getError(): ?array | ||
{ | ||
return $this->error; | ||
} | ||
|
||
public function setError(?array $error): self | ||
{ | ||
$this->error = $error; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCronJob(): ?CronJob | ||
{ | ||
return $this->cronJob; | ||
} | ||
|
||
public function setCronJob(?CronJob $cronJob): self | ||
{ | ||
$this->cronJob = $cronJob; | ||
|
||
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Draw\Component\CronJob\Message; | ||
|
||
use Draw\Component\CronJob\Entity\CronJob; | ||
use Draw\Component\Messenger\DoctrineEnvelopeEntityReference\Message\DoctrineReferenceAwareInterface; | ||
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; | ||
|
||
class ExecuteCronJobMessage implements DoctrineReferenceAwareInterface | ||
{ | ||
private ?CronJob $cronJob; | ||
|
||
public function __construct(CronJob $cronJob) | ||
{ | ||
$this->cronJob = $cronJob; | ||
} | ||
|
||
public function getCronJob(): ?CronJob | ||
{ | ||
if (null === $this->cronJob) { | ||
throw new UnrecoverableMessageHandlingException('CronJob is not set.'); | ||
} | ||
|
||
return $this->cronJob; | ||
} | ||
|
||
public function getPropertiesWithDoctrineObject(): array | ||
{ | ||
return ['cronJob']; | ||
} | ||
} |
Oops, something went wrong.