diff --git a/src/Job.php b/src/Job.php index bd16fc45..c142b0d4 100644 --- a/src/Job.php +++ b/src/Job.php @@ -96,6 +96,9 @@ public function setup(): void public function getSignature(): string { + if (!$this->URLsToProcess) { + return md5(static::class); + } return md5(implode('-', [static::class, implode('-', array_keys($this->URLsToProcess))])); } @@ -104,14 +107,16 @@ public function process(): void $chunkSize = $this->getChunkSize(); $count = 0; - foreach ($this->URLsToProcess as $url => $priority) { - $count += 1; + if ($this->URLsToProcess) { + foreach ($this->URLsToProcess as $url => $priority) { + $count += 1; - if ($chunkSize > 0 && $count > $chunkSize) { - return; - } + if ($chunkSize > 0 && $count > $chunkSize) { + return; + } - $this->processUrl($url, $priority); + $this->processUrl($url, $priority); + } } $this->updateCompletedState(); @@ -149,7 +154,7 @@ protected function markUrlAsProcessed(string $url): void */ protected function updateCompletedState(): void { - if (count($this->URLsToProcess) > 0) { + if ($this->URLsToProcess && count($this->URLsToProcess) > 0) { return; } diff --git a/tests/php/RunDeleteCacheJobTest.php b/tests/php/RunDeleteCacheJobTest.php new file mode 100644 index 00000000..bfa7519f --- /dev/null +++ b/tests/php/RunDeleteCacheJobTest.php @@ -0,0 +1,42 @@ +getJobData(); + $signature = $job->getSignature(); + $this->assertEmpty($data->jobData); + $this->assertFalse($data->isComplete); + + $job->hydrate(['/' => 1], null); + $data = $job->getJobData(); + $this->assertIsObject($data->jobData); + $this->assertFalse($data->isComplete); + $hydratedSignature = $job->getSignature(); + + // hydrating the job should affect the signature + $this->assertNotEquals($signature, $hydratedSignature); + } + + // test that the job can process regardless of URLsToProcess + public function testJobCanComplete() + { + $job = new DeleteStaticCacheJob(); + $job->process(); + $data = $job->getJobData(); + $this->assertTrue($data->isComplete); + + $job = new DeleteStaticCacheJob(); + $job->hydrate(['/' => 1], null); + $job->process(); + $data = $job->getJobData(); + $this->assertTrue($data->isComplete); + } +}