Skip to content

Commit

Permalink
[2.x] Adds support for octane:status (#115)
Browse files Browse the repository at this point in the history
* Adds `octane:status` command

* Only runs on vapor

* Only runs with Octane installed

* Update OctaneStatusCommand.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
nunomaduro and taylorotwell authored Jan 7, 2022
1 parent 7ea7c00 commit fbe8c41
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/Console/Commands/OctaneStatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Laravel\Vapor\Console\Commands;

use Illuminate\Console\Command;

class OctaneStatusCommand extends Command
{
/**
* The command's signature.
*
* @var string
*/
public $signature = 'octane:status';

/**
* The command's description.
*
* @var string
*/
public $description = 'Get the current status of the Octane server';

/**
* Handle the command.
*
* @return int
*/
public function handle()
{
$this->isEnviromentRunningOnOctane()
? $this->info('Octane server is running.')
: $this->info('Octane server is not running.');
}

/**
* Determine if the enviroment is running on Octane.
*
* @return bool
*/
protected function isEnviromentRunningOnOctane()
{
return isset($_ENV['OCTANE_DATABASE_SESSION_TTL']);
}
}
21 changes: 21 additions & 0 deletions src/VaporServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;
use Laravel\Vapor\Console\Commands\OctaneStatusCommand;
use Laravel\Vapor\Console\Commands\VaporWorkCommand;
use Laravel\Vapor\Http\Controllers\SignedStorageUrlController;
use Laravel\Vapor\Http\Middleware\ServeStaticAssets;
Expand All @@ -26,6 +27,7 @@ class VaporServiceProvider extends ServiceProvider
public function boot()
{
$this->ensureRoutesAreDefined();
$this->registerOctaneCommands();

if (($_ENV['VAPOR_SERVERLESS_DB'] ?? null) === 'true') {
Schema::defaultStringLength(191);
Expand Down Expand Up @@ -163,4 +165,23 @@ protected function registerCommands()

$this->commands(['command.vapor.work']);
}

/**
* Register the Vapor "Octane" console commands.
*
* @return void
*
* @throws \InvalidArgumentException
*/
protected function registerOctaneCommands()
{
// Ensure we are running on Vapor...
if (! isset($_ENV['VAPOR_SSM_PATH'])) {
return;
}

if ($this->app->runningInConsole()) {
$this->commands(OctaneStatusCommand::class);
}
}
}
43 changes: 43 additions & 0 deletions tests/Feature/Commands/OctaneStatusCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Laravel\Vapor\Tests\Feature\Commands;

if (! interface_exists(\Laravel\Octane\Contracts\Client::class)) {
return;
}

use Laravel\Vapor\Tests\TestCase;

class OctaneStatusCommandTest extends TestCase
{
protected function setUp(): void
{
$_ENV['VAPOR_SSM_PATH'] = 'foo';

parent::setUp();
}

public function test_when_octane_is_not_running()
{
$this->artisan('octane:status')
->assertSuccessful()
->expectsOutput('Octane server is not running.');
}

public function test_when_octane_is_running()
{
$_ENV['OCTANE_DATABASE_SESSION_TTL'] = 'false';

$this->artisan('octane:status')
->assertSuccessful()
->expectsOutput('Octane server is running.');
}

protected function tearDown(): void
{
unset($_ENV['OCTANE_DATABASE_SESSION_TTL']);
unset($_ENV['VAPOR_SSM_PATH']);

parent::tearDown();
}
}
6 changes: 5 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Vapor\Tests;

use Laravel\Octane\OctaneServiceProvider;
use Laravel\Vapor\VaporServiceProvider;
use Mockery;
use Orchestra\Testbench\TestCase as BaseTestCase;

Expand All @@ -17,6 +18,9 @@ protected function tearDown(): void

protected function getPackageProviders($app)
{
return [OctaneServiceProvider::class];
return [
OctaneServiceProvider::class,
VaporServiceProvider::class,
];
}
}

0 comments on commit fbe8c41

Please sign in to comment.