Skip to content

Commit 7e94e5e

Browse files
committed
Merge branch 'pr8742'
2 parents 0aceb68 + ab793e6 commit 7e94e5e

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

src/Illuminate/Bus/Batch.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class Batch implements Arrayable, JsonSerializable
3232
*/
3333
public $id;
3434

35+
/**
36+
* The batch name.
37+
*
38+
* @var string
39+
*/
40+
public $name;
41+
3542
/**
3643
* The total number of jobs that belong to the batch.
3744
*
@@ -94,6 +101,7 @@ class Batch implements Arrayable, JsonSerializable
94101
* @param \Illuminate\Contracts\Queue\Factory $queue
95102
* @param \Illuminate\Bus\BatchRepository $repository
96103
* @param string $id
104+
* @param string $name
97105
* @param int $totalJobs
98106
* @param int $pendingJobs
99107
* @param int $failedJobs
@@ -107,6 +115,7 @@ class Batch implements Arrayable, JsonSerializable
107115
public function __construct(QueueFactory $queue,
108116
BatchRepository $repository,
109117
string $id,
118+
string $name,
110119
int $totalJobs,
111120
int $pendingJobs,
112121
int $failedJobs,
@@ -119,6 +128,7 @@ public function __construct(QueueFactory $queue,
119128
$this->queue = $queue;
120129
$this->repository = $repository;
121130
$this->id = $id;
131+
$this->name = $name;
122132
$this->totalJobs = $totalJobs;
123133
$this->pendingJobs = $pendingJobs;
124134
$this->failedJobs = $failedJobs;
@@ -370,6 +380,7 @@ public function toArray()
370380
{
371381
return [
372382
'id' => $this->id,
383+
'name' => $this->name,
373384
'totalJobs' => $this->totalJobs,
374385
'pendingJobs' => $this->pendingJobs,
375386
'processedJobs' => $this->processedJobs(),

src/Illuminate/Bus/BatchFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(QueueFactory $queue)
3030
*
3131
* @param \Illuminate\Bus\BatchRepository $repository
3232
* @param string $id
33+
* @param string $name
3334
* @param int $totalJobs
3435
* @param int $pendingJobs
3536
* @param int $failedJobs
@@ -38,10 +39,11 @@ public function __construct(QueueFactory $queue)
3839
* @param \Illuminate\Support\CarbonImmutable $createdAt
3940
* @param \Illuminate\Support\CarbonImmutable|null $cancelledAt
4041
* @param \Illuminate\Support\CarbonImmutable|null $finishedAt
41-
* @return void
42+
* @return \Illuminate\Bus\Batch
4243
*/
4344
public function make(BatchRepository $repository,
4445
string $id,
46+
string $name,
4547
int $totalJobs,
4648
int $pendingJobs,
4749
int $failedJobs,
@@ -51,6 +53,6 @@ public function make(BatchRepository $repository,
5153
?CarbonImmutable $cancelledAt,
5254
?CarbonImmutable $finishedAt)
5355
{
54-
return new Batch($this->queue, $repository, $id, $totalJobs, $pendingJobs, $failedJobs, $failedJobIds, $options, $createdAt, $cancelledAt, $finishedAt);
56+
return new Batch($this->queue, $repository, $id, $name, $totalJobs, $pendingJobs, $failedJobs, $failedJobIds, $options, $createdAt, $cancelledAt, $finishedAt);
5557
}
5658
}

src/Illuminate/Bus/DatabaseBatchRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function store(PendingBatch $batch)
9696

9797
$this->connection->table($this->table)->insert([
9898
'id' => $id,
99+
'name' => $batch->name,
99100
'total_jobs' => 0,
100101
'pending_jobs' => 0,
101102
'failed_jobs' => 0,
@@ -253,6 +254,7 @@ protected function toBatch($batch)
253254
return $this->factory->make(
254255
$this,
255256
$batch->id,
257+
$batch->name,
256258
(int) $batch->total_jobs,
257259
(int) $batch->pending_jobs,
258260
(int) $batch->failed_jobs,

src/Illuminate/Bus/PendingBatch.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111

1212
class PendingBatch
1313
{
14+
/**
15+
* The batch name.
16+
*
17+
* @var string
18+
*/
19+
public $name = '';
20+
1421
/**
1522
* The jobs that belong to the batch.
1623
*
@@ -130,6 +137,19 @@ public function allowsFailures()
130137
return Arr::get($this->options, 'allowFailures', false) === true;
131138
}
132139

140+
/**
141+
* Set the name for the batch.
142+
*
143+
* @param string $name
144+
* @return $this
145+
*/
146+
public function name(string $name)
147+
{
148+
$this->name = $name;
149+
150+
return $this;
151+
}
152+
133153
/**
134154
* Specify the queue connection that the batched jobs should run on.
135155
*

src/Illuminate/Queue/Console/stubs/batches.stub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Create{{tableClassName}}Table extends Migration
1515
{
1616
Schema::create('{{table}}', function (Blueprint $table) {
1717
$table->string('id')->primary();
18+
$table->string('name');
1819
$table->integer('total_jobs');
1920
$table->integer('pending_jobs');
2021
$table->integer('failed_jobs');

tests/Bus/BusBatchTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function createSchema()
4646
{
4747
$this->schema()->create('job_batches', function ($table) {
4848
$table->string('id')->primary();
49+
$table->string('name');
4950
$table->integer('total_jobs');
5051
$table->integer('pending_jobs');
5152
$table->integer('failed_jobs');

0 commit comments

Comments
 (0)