-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add DummyCheckJob and related functionality
- Loading branch information
1 parent
447cc68
commit c3f4845
Showing
15 changed files
with
657 additions
and
82 deletions.
There are no files selected for viewing
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,27 @@ | ||
<?php | ||
|
||
namespace App\Jobs\Checks; | ||
|
||
use App\Enums\Checks\Status; | ||
use App\Models\Monitor; | ||
|
||
class DummyCheckJob extends CheckJob | ||
{ | ||
private Status $returnStatus; | ||
|
||
public function __construct(Monitor $monitor, Status $returnStatus = Status::OK) | ||
{ | ||
parent::__construct($monitor); | ||
$this->returnStatus = $returnStatus; | ||
} | ||
|
||
protected function performCheck(): array | ||
{ | ||
usleep(random_int(100000, 123456)); | ||
return [ | ||
'status' => $this->returnStatus, | ||
'response_code' => 200, | ||
'output' => 'test 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
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,50 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use Exception; | ||
|
||
class TcpConnectionService | ||
{ | ||
/** | ||
* Open a TCP connection to the given host and port | ||
* | ||
* @param string $hostname | ||
* @param int $port | ||
* @param int $timeout | ||
* @return resource | ||
* @throws Exception | ||
*/ | ||
public function connect(string $hostname, int $port, int $timeout = 5) | ||
{ | ||
$errno = 0; | ||
$errstr = ''; | ||
|
||
$socket = @fsockopen( | ||
$hostname, | ||
$port, | ||
$errno, | ||
$errstr, | ||
timeout: $timeout | ||
); | ||
|
||
if (!$socket) { | ||
throw new Exception($errstr, $errno); | ||
} | ||
|
||
return $socket; | ||
} | ||
|
||
/** | ||
* Close a TCP connection | ||
* | ||
* @param resource $socket | ||
* @return void | ||
*/ | ||
public function close($socket): void | ||
{ | ||
if (is_resource($socket)) { | ||
fclose($socket); | ||
} | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Enums\Checks\Status; | ||
use App\Models\Monitor; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Symfony\Component\Uid\Ulid; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Check> | ||
*/ | ||
class CheckFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'id' => Ulid::generate(), | ||
'status' => Status::OK, | ||
'checked_at' => now(), | ||
'monitor_id' => Monitor::factory(), | ||
]; | ||
} | ||
} |
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
Oops, something went wrong.