Skip to content

Commit ddb89f5

Browse files
committed
Add onGroup and withDeduplicator to Queueable trait and PendingDispatch
1 parent 6ee7d6f commit ddb89f5

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/bus/src/PendingDispatch.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ public function onQueue(UnitEnum|string|null $queue): static
4747
return $this;
4848
}
4949

50+
/**
51+
* Set the desired job "group".
52+
*
53+
* This feature is only supported by some queues, such as Amazon SQS.
54+
*/
55+
public function onGroup(UnitEnum|string $group): static
56+
{
57+
$this->job->onGroup($group);
58+
59+
return $this;
60+
}
61+
62+
/**
63+
* Set the desired job deduplicator callback.
64+
*
65+
* This feature is only supported by some queues, such as Amazon SQS FIFO.
66+
*/
67+
public function withDeduplicator(?callable $deduplicator): static
68+
{
69+
$this->job->withDeduplicator($deduplicator);
70+
71+
return $this;
72+
}
73+
5074
/**
5175
* Set the desired connection for the chain.
5276
*/

src/bus/src/Queueable.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Hypervel\Queue\CallQueuedClosure;
1111
use Hypervel\Support\Arr;
1212
use Hypervel\Support\Collection;
13+
use Laravel\SerializableClosure\SerializableClosure;
1314
use PHPUnit\Framework\Assert as PHPUnit;
1415
use RuntimeException;
1516
use Throwable;
@@ -29,6 +30,18 @@ trait Queueable
2930
*/
3031
public ?string $queue = null;
3132

33+
/**
34+
* The job "group" the job should be sent to.
35+
*/
36+
public ?string $messageGroup = null;
37+
38+
/**
39+
* The job deduplicator callback the job should use to generate the deduplication ID.
40+
*
41+
* @var \Laravel\SerializableClosure\SerializableClosure|null
42+
*/
43+
public $deduplicator = null;
44+
3245
/**
3346
* The number of seconds before the job should be made available.
3447
*/
@@ -88,6 +101,32 @@ public function onQueue(UnitEnum|string|null $queue): static
88101
return $this;
89102
}
90103

104+
/**
105+
* Set the desired job "group".
106+
*
107+
* This feature is only supported by some queues, such as Amazon SQS.
108+
*/
109+
public function onGroup(UnitEnum|string $group): static
110+
{
111+
$this->messageGroup = enum_value($group);
112+
113+
return $this;
114+
}
115+
116+
/**
117+
* Set the desired job deduplicator callback.
118+
*
119+
* This feature is only supported by some queues, such as Amazon SQS FIFO.
120+
*/
121+
public function withDeduplicator(?callable $deduplicator): static
122+
{
123+
$this->deduplicator = $deduplicator instanceof Closure
124+
? new SerializableClosure($deduplicator)
125+
: $deduplicator;
126+
127+
return $this;
128+
}
129+
91130
/**
92131
* Set the desired connection for the chain.
93132
*/

0 commit comments

Comments
 (0)