Skip to content

Commit ce98617

Browse files
Extends the default Schedule Run Command
1 parent 67498d8 commit ce98617

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"require": {
2222
"php": "^7.4|^8.0",
23+
"illuminate/console": "^8.0|^9.0|^10.0",
2324
"illuminate/queue": "^8.0|^9.0|^10.0",
2425
"illuminate/support": "^8.0|^9.0|^10.0",
2526
"kainxspirits/laravel-pubsub-queue": "^0.6|^0.7|^0.8"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace RichanFongdasen\GCRWorker\Console\Commands;
4+
5+
use Illuminate\Console\Scheduling\ScheduleRunCommand as BaseScheduleRunCommand;
6+
7+
class ScheduleRunCommand extends BaseScheduleRunCommand
8+
{
9+
/**
10+
* The console command name.
11+
*
12+
* @var string
13+
*/
14+
protected $name = 'gcr-schedule:run';
15+
16+
/**
17+
* Create a new command instance.
18+
*
19+
* @return void
20+
*/
21+
public function __construct()
22+
{
23+
parent::__construct();
24+
25+
$this->fixStartTime();
26+
}
27+
28+
/**
29+
* Fix the start time of the command.
30+
*
31+
* @return void
32+
*/
33+
protected function fixStartTime(): void
34+
{
35+
$this->startedAt->second(0);
36+
}
37+
}

src/Controllers/ScheduledJobController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ public function index(): JsonResponse
4242
$this->increaseExecutionTime();
4343
$this->increaseMemoryLimit();
4444

45-
Artisan::call('schedule:run');
45+
Artisan::call('gcr-schedule:run');
4646

47-
$response = [
47+
return response()->json([
4848
'info' => 'The scheduled job has completed.',
49-
];
50-
51-
return response()->json($reponse);
49+
]);
5250
}
5351
}

src/ServiceProvider.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Facades\Route;
66
use Illuminate\Support\ServiceProvider as Provider;
7+
use RichanFongdasen\GCRWorker\Console\Commands\ScheduleRunCommand;
78

89
class ServiceProvider extends Provider
910
{
@@ -33,6 +34,20 @@ public function register(): void
3334
if ($configPath !== false) {
3435
$this->mergeConfigFrom($configPath, 'gcr-worker');
3536
}
37+
38+
$this->registerCommands();
39+
}
40+
41+
/**
42+
* Register the package's console commands.
43+
*
44+
* @return void
45+
*/
46+
protected function registerCommands(): void
47+
{
48+
$this->commands([
49+
ScheduleRunCommand::class,
50+
]);
3651
}
3752

3853
/**

tests/Feature/ScheduledJobHandlingTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ public function it_can_handle_scheduled_job_invocation_as_expected()
2020
{
2121
config(['gcr-worker.allow_event_invocation' => true]);
2222

23-
$artisan = \Mockery::mock(Kernel::class);
24-
app()->bind(KernelContract::class, function () use ($artisan) {
25-
return $artisan;
26-
});
27-
28-
$artisan->shouldReceive('call')
29-
->withArgs(['schedule:run'])
30-
->once();
31-
3223
$this->getJson('/gcr-worker/run-scheduled-job')
3324
->assertStatus(200)
3425
->assertJsonFragment(['info' => 'The scheduled job has completed.']);

0 commit comments

Comments
 (0)