Revert "exploring address pinging"

This reverts commit 90978bca9f.
This commit is contained in:
Alex Justesen
2022-12-18 08:46:55 -05:00
parent 90978bca9f
commit 6fb404fb1e
8 changed files with 0 additions and 262 deletions
-50
View File
@@ -1,50 +0,0 @@
<?php
namespace App\Jobs;
use App\Models\PingAddress;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class PingAddressCommand implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(
public PingAddress $pingAddress
) {}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// https://github.com/striebwj/laravel-ping/blob/master/src/LaravelPing.php
// create a new cURL resource
$ch = curl_init($this->pingAddress->url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Speedtest Tracker (https://docs.speedtest-tracker.dev)');
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
curl_exec($ch);
$data = curl_getinfo($ch);
// close cURL resource, and free up system resources
curl_close($ch);
}
}
-46
View File
@@ -1,46 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Ping extends Model
{
use HasFactory;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'http_code',
'total_time',
'data',
'is_successful',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'is_scheduled' => 'boolean',
'data' => 'array',
'created_at' => 'datetime',
];
public function address()
{
return $this->belongsTo(PingAddress::class, 'address_id');
}
}
-27
View File
@@ -1,27 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PingAddress extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'url',
'max_redirects',
'timeout',
];
public function pings()
{
return $this->hasMany(Ping::class, 'address_id');
}
}
-23
View File
@@ -1,23 +0,0 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PingAddress>
*/
class PingAddressFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
//
];
}
}
-23
View File
@@ -1,23 +0,0 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Ping>
*/
class PingFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
//
];
}
}
@@ -1,34 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('ping_addresses', function (Blueprint $table) {
$table->id();
$table->string('url');
$table->integer('max_redirects')->default(5);
$table->integer('timeout')->default(5);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('ping_addresses');
}
};
@@ -1,36 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pings', function (Blueprint $table) {
$table->id();
$table->foreignId('address_id');
$table->integer('http_code')->nullable();
$table->float('total_time')->nullable();
$table->boolean('is_successful')->default(false);
$table->json('data')->nullable(); // is a dump of the curl_getinfo() function
$table->timestamp('created_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pings');
}
};
-23
View File
@@ -1,6 +1,5 @@
<?php
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;
Route::group(
@@ -9,27 +8,5 @@ Route::group(
],
function () {
// silence is golden
Route::get('/', function () {
// https://github.com/striebwj/laravel-ping/blob/master/src/LaravelPing.php
// create a new cURL resource
$ch = curl_init('https://alexjustesen.com/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Speedtest Tracker (https://docs.speedtest-tracker.dev)');
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
curl_exec($ch);
$data = curl_getinfo($ch);
// close cURL resource, and free up system resources
curl_close($ch);
dd($data);
});
}
);