Fix status checker last call

This commit is contained in:
Vincent BRIDIER 2022-09-22 13:56:33 +02:00
parent 5fd90b7cbc
commit 74c17eaa3f
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
4 changed files with 40 additions and 3 deletions

View file

@ -21,6 +21,7 @@ class StatusCheckerController extends Controller
->firstOrNew();
$project_sc->fill($request->validated());
$project_sc->last_call = \now();
return $project_sc->save() ? response('OK') : response('KO');
}
}

View file

@ -128,11 +128,11 @@ class Project extends Model
*/
public function getCheckedAttribute()
{
$value = ProjectStatusChecker::select('updated_at')->where('project_uuid', '=', $this->uuid)->first();
$value = ProjectStatusChecker::select('last_call')->where('project_uuid', '=', $this->uuid)->first();
if (!$value) {
$value = 'missing';
} else {
$value = $value->updated_at;
$value = $value->last_call;
$dt = Carbon::now();
if ($dt->diffInMinutes($value) > 30) {
$value = 'false';

View file

@ -23,6 +23,6 @@ class ProjectStatusChecker extends Model
* @var array
*/
protected $fillable = [
'project_uuid', 'code', 'sitemap', 'robots', 'logs'
'project_uuid', 'code', 'sitemap', 'robots', 'logs', 'last_call'
];
}

View file

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AlterStatuscheckerTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('project_status_checkers', function (Blueprint $table) {
$table->unsignedSmallInteger('sitemap')->comment('Has sitemap ?')->change();
$table->unsignedSmallInteger('robots')->comment('Has robots.txt ?')->change();
$table->dateTime('last_call')->default('1970-01-01')->comment('Last API call date')->after('logs');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('project_status_checkers', function (Blueprint $table) {
$table->string('sitemap', 20)->change();
$table->string('robots', 20)->change();
$table->dropColumn('last_call');
});
}
}