Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7eecb78

Browse filesBrowse files
[12.x] Add a command option for making batchable jobs (#55929)
* add a command option for making batchable jobs * Update JobMakeCommand.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 42c39f0 commit 7eecb78
Copy full SHA for 7eecb78

File tree

Expand file treeCollapse file tree

2 files changed

+40
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-1
lines changed

‎src/Illuminate/Foundation/Console/JobMakeCommand.php

Copy file name to clipboardExpand all lines: src/Illuminate/Foundation/Console/JobMakeCommand.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class JobMakeCommand extends GeneratorCommand
4040
*/
4141
protected function getStub()
4242
{
43+
if ($this->option('batched')) {
44+
return $this->resolveStubPath('/stubs/job.batched.queued.stub');
45+
}
46+
4347
return $this->option('sync')
4448
? $this->resolveStubPath('/stubs/job.stub')
4549
: $this->resolveStubPath('/stubs/job.queued.stub');
@@ -78,7 +82,8 @@ protected function getOptions()
7882
{
7983
return [
8084
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the job already exists'],
81-
['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous'],
85+
['sync', null, InputOption::VALUE_NONE, 'Indicates that the job should be synchronous'],
86+
['batched', null, InputOption::VALUE_NONE, 'Indicates that the job should be batchable'],
8287
];
8388
}
8489
}
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use Illuminate\Bus\Batchable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Foundation\Queue\Queueable;
8+
9+
class {{ class }} implements ShouldQueue
10+
{
11+
use Batchable, Queueable;
12+
13+
/**
14+
* Create a new job instance.
15+
*/
16+
public function __construct()
17+
{
18+
//
19+
}
20+
21+
/**
22+
* Execute the job.
23+
*/
24+
public function handle(): void
25+
{
26+
if ($this->batch()->cancelled()) {
27+
// The batch has been cancelled...
28+
29+
return;
30+
}
31+
32+
//
33+
}
34+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.