Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jan 1, 2021
1 parent d25cdfc commit 01790b7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Spatie\Ray;

use Exception;
use Spatie\Ray\Exceptions\CouldNotConnectToRay;
use Spatie\Ray\Exceptions\StopExecutionRequested;

class Client
{
Expand Down Expand Up @@ -43,9 +45,18 @@ public function lockExists(string $lockName): bool

$response = json_decode($curlResult, true);

if ($response['stop_execution'] ?? false) {
throw StopExecutionRequested::make();
}

return $response['active'] ?? false;

} catch (Exception $exception) {
throw new Exception("Ray seems not be running at {$this->host}:{$this->portNumber}");
if ($exception instanceof StopExecutionRequested) {
throw $exception;
}

throw CouldNotConnectToRay::make($this->host, $this->portNumber);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/Exceptions/CouldNotConnectToRay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Spatie\Ray\Exceptions;

use Exception;

class CouldNotConnectToRay extends Exception
{
public static function make(string $host, int $portNumber): self
{
return new static("Couldn't connect to Ray It doesn't seem to be running at {$host}:{$portNumber}");
}
}
13 changes: 13 additions & 0 deletions src/Exceptions/StopExecutionRequested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Spatie\Ray\Exceptions;

use Exception;

class StopExecutionRequested extends Exception
{
public static function make(): self
{
return new static("This exception is thrown because you requested to stop the execution in Ray.");
}
}

0 comments on commit 01790b7

Please sign in to comment.