Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit b62f5e9

Browse files
authored
Merge pull request #12 from lucid-architecture/queueable_jobs
Queueable jobs
2 parents a824290 + ef81d59 commit b62f5e9

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To do that, put this in your shell profile (~/.bash_profile, ~/.zshrc, ~/bashrc)
3838
#### Make
3939
- `make:controller <controller> [<service>]`
4040
- `make:feature <feature> [<service>]`
41-
- `make:job <job> <domain>`
41+
- `make:job <job> <domain> [--queue]`
4242
- `make:service <name>`
4343
- `make:model <model>`
4444
- `make:request <request> [<service>]`

src/Commands/JobMakeCommand.php

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

1212
namespace Lucid\Console\Commands;
1313

14-
use Lucid\Console\Str;
15-
use Lucid\Console\Finder;
1614
use Lucid\Console\Command;
1715
use Lucid\Console\Filesystem;
16+
use Lucid\Console\Finder;
1817
use Lucid\Console\Generators\JobGenerator;
19-
use Symfony\Component\Console\Input\InputArgument;
18+
use Lucid\Console\Str;
2019
use Symfony\Component\Console\Command\Command as SymfonyCommand;
20+
use Symfony\Component\Console\Input\InputArgument;
21+
use Symfony\Component\Console\Input\InputOption;
2122

2223
/**
2324
* @author Abed Halawi <[email protected]>
@@ -33,7 +34,7 @@ class JobMakeCommand extends SymfonyCommand
3334
*
3435
* @var string
3536
*/
36-
protected $name = 'make:job';
37+
protected $name = 'make:job {--Q|queue}';
3738

3839
/**
3940
* The console command description.
@@ -60,9 +61,9 @@ public function fire()
6061

6162
$domain = studly_case($this->argument('domain'));
6263
$title = $this->parseName($this->argument('job'));
63-
64+
$isQueueable = $this->option('queue');
6465
try {
65-
$job = $generator->generate($title, $domain);
66+
$job = $generator->generate($title, $domain, $isQueueable);
6667

6768
$this->info(
6869
'Job class '.$title.' created successfully.'.
@@ -83,6 +84,13 @@ public function getArguments()
8384
];
8485
}
8586

87+
public function getOptions()
88+
{
89+
return [
90+
['queue', 'Q', InputOption::VALUE_NONE, 'Whether a job is queueable or not.'],
91+
];
92+
}
93+
8694
/**
8795
* Get the stub file for the generator.
8896
*

src/Generators/JobGenerator.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class JobGenerator extends Generator
2222
{
23-
public function generate($job, $domain)
23+
public function generate($job, $domain, $isQueueable = false)
2424
{
2525
$job = Str::job($job);
2626
$domain = Str::domain($domain);
@@ -38,7 +38,7 @@ public function generate($job, $domain)
3838
// Create the job
3939
$namespace = $this->findDomainJobsNamespace($domain);
4040

41-
$content = file_get_contents($this->getStub());
41+
$content = file_get_contents($this->getStub($isQueueable));
4242
$content = str_replace(
4343
['{{job}}', '{{namespace}}', '{{foundation_namespace}}'],
4444
[$job, $namespace, $this->findFoundationNamespace()],
@@ -101,9 +101,15 @@ private function createDomainDirectory($domain)
101101
*
102102
* @return string
103103
*/
104-
public function getStub()
104+
public function getStub($isQueueable = false)
105105
{
106-
return __DIR__.'/stubs/job.stub';
106+
$stubName;
107+
if ($isQueueable) {
108+
$stubName = '/stubs/queueable-job.stub';
109+
} else {
110+
$stubName = '/stubs/job.stub';
111+
}
112+
return __DIR__.$stubName;
107113
}
108114

109115
/**

src/Generators/stubs/job.stub

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ use {{foundation_namespace}}\Job;
55

66
class {{job}} extends Job
77
{
8+
/**
9+
* Create a new job instance.
10+
*
11+
* @return void
12+
*/
813
public function __construct()
914
{
10-
15+
//
1116
}
1217

18+
/**
19+
* Execute the job.
20+
*
21+
* @return void
22+
*/
1323
public function handle()
1424
{
15-
25+
//
1626
}
1727
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
namespace {{namespace}};
3+
4+
use {{foundation_namespace}}\QueueableJob;
5+
6+
class {{job}} extends QueueableJob
7+
{
8+
/**
9+
* Create a new job instance.
10+
*
11+
* @return void
12+
*/
13+
public function __construct()
14+
{
15+
//
16+
}
17+
18+
/**
19+
* Execute the job.
20+
*
21+
* @return void
22+
*/
23+
public function handle()
24+
{
25+
//
26+
}
27+
}

0 commit comments

Comments
 (0)