Skip to content

Commit

Permalink
Fix dispatch signature
Browse files Browse the repository at this point in the history
  • Loading branch information
chapterjason committed Dec 8, 2023
1 parent 2be7881 commit 8eb8c74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/Manager/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ private function escapeArgument(?string $argument): string
return '"' . str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument) . '"';
}

public function dispatch(Job $job): void
public function dispatch(string|object $entityOrIdentity, object $payload): Job
{
$pendingJobs = $this->jobRepository->getPendingByJob($job);
$pendingJobs = $this->jobRepository->getPending($entityOrIdentity, $payload);

if (count($pendingJobs) > 0) {
throw new LogicException("Job with identity already queued.");
}

$job = $this->create($entityOrIdentity, $payload);

$command = [
...$this->getPhpBinary(),
Path::join($this->projectDirectory, 'bin', 'console'),
Expand All @@ -95,6 +97,8 @@ public function dispatch(Job $job): void

// $process->disableOutput();
$process->start();

return $job;
}

protected function getPhpBinary(): ?array
Expand Down
4 changes: 1 addition & 3 deletions tests/CancelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ public function testCancel(): void
$entityManager->persist($entity);
$entityManager->flush();

$job = $jobManager->create($entity, new WaitJob(10));

$now = new \DateTime();
$jobManager->dispatch($job);
$job = $jobManager->dispatch($entity, new WaitJob(10));
$after = new \DateTime();
$diff = $after->getTimestamp() - $now->getTimestamp();

Expand Down
11 changes: 3 additions & 8 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ public function testWaitJobDispatchAndExecution(): void
$entityManager->persist($entity);
$entityManager->flush();

$job = $jobManager->create($entity, new WaitJob());

self::assertTrue($job->isPending());

$now = new \DateTime();
$jobManager->dispatch($job);
$job = $jobManager->dispatch($entity, new WaitJob());
self::assertTrue($job->isPending());
$after = new \DateTime();
$diff = $after->getTimestamp() - $now->getTimestamp();

Expand Down Expand Up @@ -100,10 +97,8 @@ public function testFastJobDispatchExecutionAndResult(): void
$entityManager->persist($entity);
$entityManager->flush();

$job = $jobManager->create($entity, new FastJob("yeet"));

$now = new \DateTime();
$jobManager->dispatch($job);
$job = $jobManager->dispatch($entity, new FastJob("yeet"));
$after = new \DateTime();
$diff = $after->getTimestamp() - $now->getTimestamp();

Expand Down

0 comments on commit 8eb8c74

Please sign in to comment.