-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use database for kvp storage * Read kvpstore * Add web cron ability through API #821 * Style fixes * Fix text
- Loading branch information
Showing
13 changed files
with
243 additions
and
3 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
app/Database/migrations/2021_03_05_044305_add_kvp_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use App\Contracts\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
/** | ||
* Add a hub to the subfleet is | ||
*/ | ||
class AddKvpTable extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('kvp', function (Blueprint $table) { | ||
$table->string('key')->index(); | ||
$table->string('value'); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
class CronInvalid extends AbstractHttpException | ||
{ | ||
public const MESSAGE = 'Cron ID is disabled or invalid'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(400, static::MESSAGE); | ||
} | ||
|
||
/** | ||
* Return the RFC 7807 error type (without the URL root) | ||
*/ | ||
public function getErrorType(): string | ||
{ | ||
return 'cron-invalid'; | ||
} | ||
|
||
/** | ||
* Get the detailed error string | ||
*/ | ||
public function getErrorDetails(): string | ||
{ | ||
return $this->getMessage(); | ||
} | ||
|
||
/** | ||
* Return an array with the error details, merged with the RFC7807 response | ||
*/ | ||
public function getErrorMetadata(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Contracts\Controller; | ||
use App\Exceptions\CronInvalid; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Artisan; | ||
|
||
class MaintenanceController extends Controller | ||
{ | ||
/** | ||
* Run the cron job from the web | ||
* | ||
* @param Request $request | ||
* @param string $id The ID passed in for the cron | ||
* | ||
* @return mixed | ||
*/ | ||
public function cron(Request $request, string $id) | ||
{ | ||
$cron_id = setting('cron.random_id'); | ||
if (empty($cron_id) || $id !== $cron_id) { | ||
throw new CronInvalid(); | ||
} | ||
|
||
$output = ''; | ||
Artisan::call('schedule:run'); | ||
$output .= trim(Artisan::output()); | ||
|
||
return response([ | ||
'content' => $output, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Contracts\Model; | ||
|
||
/** | ||
* @property string key | ||
* @property string value | ||
*/ | ||
class Kvp extends Model | ||
{ | ||
public $table = 'kvp'; | ||
public $timestamps = false; | ||
public $incrementing = false; | ||
|
||
protected $keyType = 'string'; | ||
|
||
public $fillable = [ | ||
'key', | ||
'value', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters