Skip to content

Commit

Permalink
Lazily initialize Job uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Nov 14, 2023
1 parent 73ba000 commit ba5c6e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 0 additions & 6 deletions application/clicommands/JobsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use ipl\Scheduler\Contract\Frequency;
use ipl\Scheduler\Scheduler;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;
use React\EventLoop\Loop;
use React\Promise\ExtendedPromiseInterface;
use stdClass;
Expand Down Expand Up @@ -180,11 +179,6 @@ protected function fetchSchedules(?string $jobName, ?string $scheduleName): arra
->setId($jobConfig->id)
->setExcludes($this->parseExcludes($jobConfig->exclude_targets));

// The Job class sets the uuid in its constructor, but since the excluded targets are also hashed as
// part of the job's uuid and the excluded targets are set after the job construction, we have to
// reset the uuid afterwards. Otherwise, it won't notice when updating the "exclude_targets" column.
$job->setUuid(Uuid::fromBytes($job->getChecksum()));

$jobSchedules[$job->getUuid()->toString()] = $job;
}

Expand Down
11 changes: 10 additions & 1 deletion library/X509/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ipl\Stdlib\Filter;
use LogicException;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use React\EventLoop\Loop;
use React\Promise;
use React\Socket\ConnectionInterface;
Expand Down Expand Up @@ -110,7 +111,6 @@ public function __construct(string $name, array $cidrs, array $ports, array $sni
}

$this->setName($name);
$this->setUuid(Uuid::fromBytes($this->getChecksum()));
}

/**
Expand Down Expand Up @@ -207,6 +207,15 @@ public function setId(int $id): self
return $this;
}

public function getUuid(): UuidInterface
{
if (! $this->uuid) {
$this->setUuid(Uuid::fromBytes($this->getChecksum()));
}

return $this->uuid;
}

/**
* Get the configured job CIDRS
*
Expand Down

0 comments on commit ba5c6e3

Please sign in to comment.