Skip to content

Commit

Permalink
Merge branch '6.1' into 6
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 28, 2023
2 parents 7ffd004 + 85394b4 commit fb99980
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))]));
}

Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down
42 changes: 42 additions & 0 deletions tests/php/RunDeleteCacheJobTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace SilverStripe\StaticPublishQueue\Job;

use SilverStripe\Dev\FunctionalTest;
use Symbiote\QueuedJobs\Services\QueuedJobService;

class RunDeleteCacheJobTest extends FunctionalTest
{
public function testHydrationAffectsSignature()
{
$job = new DeleteStaticCacheJob();
$data = $job->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);
}
}

0 comments on commit fb99980

Please sign in to comment.