Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function canIUse(string $context = null): bool
$this->queue->channel = 'queue';
$reserved = $this->queue->getTotalReserved();
} catch (\Exception) {
$reserved = 0;
$this->increment();
return false;
}

$currentUsage = $this->internalCount + $reserved;
Expand Down
19 changes: 19 additions & 0 deletions tests/RateLimiterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,23 @@ public function getTotalReserved(): int

$this->assertSame(0, $this->plugin->getRateLimiter()->getInternalCount());
}


public function test_stop_spawning_processes_when_counting_jobs_failed(): void
{
// Fake the reserved count
$queue = new class extends \craft\queue\Queue {
public function getTotalReserved(): int
{
throw new \Exception('Unable to count jobs');
}
};

$this->plugin->set('async_rate_limiter', new \ostark\AsyncQueue\RateLimiter($queue, $this->plugin->getSettings()));
$handler = new \ostark\AsyncQueue\Handlers\BackgroundQueueHandler($this->plugin);

$handler->__invoke(new PushEvent());

$this->assertFalse($this->plugin->getRateLimiter()->canIUse());
}
}