mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 13:23:04 +01:00
Moved job over to facade
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Events\SpeedtestFailedEvent;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use Exception;
|
||||
use Healthcheck;
|
||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@@ -19,16 +20,29 @@ class SpeedtestJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Scheduled bool
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $scheduled;
|
||||
|
||||
/**
|
||||
* Integrations config array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($scheduled = true)
|
||||
public function __construct($scheduled = true, $config = [])
|
||||
{
|
||||
$this->scheduled = $scheduled;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,38 +52,49 @@ class SpeedtestJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$healthchecksEnabled = (bool)SettingsHelper::get('healthchecks_enabled')->value;
|
||||
$healthchecksUuid = SettingsHelper::get('healthchecks_uuid')->value;
|
||||
|
||||
if($healthchecksEnabled === true) {
|
||||
try {
|
||||
$hc = new Healthchecks($healthchecksUuid);
|
||||
$hc->start();
|
||||
} catch(Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
if($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('start');
|
||||
}
|
||||
$output = SpeedtestHelper::output();
|
||||
$speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled);
|
||||
if($speedtest == false) {
|
||||
if(isset($hc)) {
|
||||
try {
|
||||
$hc->fail();
|
||||
} catch(Exception $e) {
|
||||
//
|
||||
}
|
||||
if($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('fail');
|
||||
}
|
||||
|
||||
event(new SpeedtestFailedEvent());
|
||||
} else {
|
||||
if(isset($hc)) {
|
||||
try {
|
||||
$hc->success();
|
||||
} catch(Exception $e) {
|
||||
//
|
||||
}
|
||||
if($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('success');
|
||||
}
|
||||
|
||||
event(new SpeedtestCompleteEvent($speedtest));
|
||||
}
|
||||
return $speedtest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to reduce duplication of try/catch for hc
|
||||
*
|
||||
* @param String $method
|
||||
* @return void
|
||||
*/
|
||||
private function healthcheck(String $method)
|
||||
{
|
||||
try {
|
||||
if($method === 'start') {
|
||||
Healthcheck::start();
|
||||
}
|
||||
|
||||
if($method === 'success') {
|
||||
Healthcheck::success();
|
||||
}
|
||||
|
||||
if($method === 'fail') {
|
||||
Healthcheck::fail();
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"tymon/jwt-auth": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-ide-helper": "^2.8",
|
||||
"facade/ignition": "^2.0",
|
||||
"fzaninotto/faker": "^1.9.1",
|
||||
"mockery/mockery": "^1.3.1",
|
||||
|
||||
131
composer.lock
generated
131
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "837c814b9f3c208c35d3e28d611623fa",
|
||||
"content-hash": "94fffe1900e25fd9ab781c8dd9ebab35",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
@@ -5375,6 +5375,135 @@
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "barryvdh/laravel-ide-helper",
|
||||
"version": "v2.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/barryvdh/laravel-ide-helper.git",
|
||||
"reference": "ba95d18ef55c91295250ae8b7bfa73d8fb866b9b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/barryvdh/laravel-ide-helper/zipball/ba95d18ef55c91295250ae8b7bfa73d8fb866b9b",
|
||||
"reference": "ba95d18ef55c91295250ae8b7bfa73d8fb866b9b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"barryvdh/reflection-docblock": "^2.0.6",
|
||||
"composer/composer": "^1.6 || ^2.0@dev",
|
||||
"doctrine/dbal": "~2.3",
|
||||
"illuminate/console": "^5.5 || ^6 || ^7",
|
||||
"illuminate/filesystem": "^5.5 || ^6 || ^7",
|
||||
"illuminate/support": "^5.5 || ^6 || ^7",
|
||||
"php": ">=7.2",
|
||||
"phpdocumentor/type-resolver": "^1.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/config": "^5.5 || ^6 || ^7",
|
||||
"illuminate/view": "^5.5 || ^6 || ^7",
|
||||
"mockery/mockery": "^1.3",
|
||||
"orchestra/testbench": "^3.5 || ^4 || ^5",
|
||||
"phpro/grumphp": "^0.19.0",
|
||||
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
"vimeo/psalm": "^3.12"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.7-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Barryvdh\\LaravelIdeHelper\\IdeHelperServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Barryvdh\\LaravelIdeHelper\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Barry vd. Heuvel",
|
||||
"email": "barryvdh@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.",
|
||||
"keywords": [
|
||||
"autocomplete",
|
||||
"codeintel",
|
||||
"helper",
|
||||
"ide",
|
||||
"laravel",
|
||||
"netbeans",
|
||||
"phpdoc",
|
||||
"phpstorm",
|
||||
"sublime"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/barryvdh",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-08-10T08:22:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "barryvdh/reflection-docblock",
|
||||
"version": "v2.0.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/barryvdh/ReflectionDocBlock.git",
|
||||
"reference": "6b69015d83d3daf9004a71a89f26e27d27ef6a16"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/barryvdh/ReflectionDocBlock/zipball/6b69015d83d3daf9004a71a89f26e27d27ef6a16",
|
||||
"reference": "6b69015d83d3daf9004a71a89f26e27d27ef6a16",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0,<4.5"
|
||||
},
|
||||
"suggest": {
|
||||
"dflydev/markdown": "~1.0",
|
||||
"erusev/parsedown": "~1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Barryvdh": [
|
||||
"src/"
|
||||
]
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mike van Riel",
|
||||
"email": "mike.vanriel@naenius.com"
|
||||
}
|
||||
],
|
||||
"time": "2018-12-13T10:34:14+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/ca-bundle",
|
||||
"version": "1.2.7",
|
||||
|
||||
Reference in New Issue
Block a user