Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/Illuminate/Foundation/Console/JobMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class JobMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
if ($this->option('batched')) {
return $this->resolveStubPath('/stubs/job.batched.queued.stub');
}

return $this->option('sync')
? $this->resolveStubPath('/stubs/job.stub')
: $this->resolveStubPath('/stubs/job.queued.stub');
Expand Down Expand Up @@ -78,7 +82,8 @@ protected function getOptions()
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the job already exists'],
['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous'],
['sync', null, InputOption::VALUE_NONE, 'Indicates that the job should be synchronous'],
['batched', null, InputOption::VALUE_NONE, 'Indicates that the job should be batchable'],
];
}
}
34 changes: 34 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/job.batched.queued.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace {{ namespace }};

use Illuminate\Bus\Batchable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class {{ class }} implements ShouldQueue
{
use Batchable, Queueable;

/**
* Create a new job instance.
*/
public function __construct()
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
if ($this->batch()->cancelled()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong. Just because a job can be batched, doesn't necessarily mean that it will be batched. It's possible that it can be dispatched to the queue on it's own. In that case $this->batch() will return null.

Suggested change
if ($this->batch()->cancelled()) {
if ($this->batch()?->cancelled()) {

// The batch has been cancelled...

return;
}

//
}
}