-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathManager.php
More file actions
37 lines (30 loc) · 910 Bytes
/
Manager.php
File metadata and controls
37 lines (30 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Utopia\Queue\Concurrency;
use Utopia\Queue\Message;
abstract class Manager
{
public function __construct(protected Adapter $adapter, protected int $limit = 1)
{
}
public function canProcessJob(Message $message): bool
{
$key = $this->getConcurrencyKey($message);
$value = $this->adapter->get($key);
if ($value === null) {
$this->adapter->set($key, "0");
$value = 0;
}
return \intval($value) < $this->limit;
}
public function startJob(Message $message): void
{
$key = $this->getConcurrencyKey($message);
$this->adapter->increment($key);
}
public function finishJob(Message $message): void
{
$key = $this->getConcurrencyKey($message);
$this->adapter->decrement($key);
}
abstract public function getConcurrencyKey(Message $message): string;
}