- WIP on Task scheduling interface
This commit is contained in:
parent
586f2344df
commit
5a737c06c4
|
@ -45,7 +45,7 @@ namespace Negundo\Client {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
if (! function_exists('ntask') ) {
|
if (! function_exists('ntask') ) {
|
||||||
function ntask(string $message, ? string $title = null, ? array $data = null) {
|
function ntask(string $message, ? string $title = null, ? array $data = null, ? Negundo\Client\Task\StatusEnum $status = null) {
|
||||||
foreach (\Negundo\Client\Task::$instances as $instance) {
|
foreach (\Negundo\Client\Task::$instances as $instance) {
|
||||||
$sent = $instance->newReport($message, $title, $data);
|
$sent = $instance->newReport($message, $title, $data);
|
||||||
|
|
||||||
|
@ -55,4 +55,4 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Negundo\Client\Task;
|
||||||
|
|
||||||
|
enum StatusEnum : string
|
||||||
|
{
|
||||||
|
case Completed = "completed";
|
||||||
|
case Failed = "failed";
|
||||||
|
case Warning = "warning";
|
||||||
|
}
|
|
@ -26,15 +26,22 @@ class Curl implements TransportInterface {
|
||||||
|
|
||||||
$exec = curl_exec($ch);
|
$exec = curl_exec($ch);
|
||||||
|
|
||||||
if ( ( false === $exec ) && $this->throwErrors ) {
|
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||||
$errno = curl_errno($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
throw new CurlException(implode(PHP_EOL, array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ])), $errno);
|
if ($this->throwErrors) {
|
||||||
|
if ( false === $exec) {
|
||||||
|
$errno = curl_errno($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
throw new CurlException(implode(PHP_EOL, array_filter([ curl_error($ch) , static::CURL_ERROR[$errno] ?? null ])), $errno);
|
||||||
|
}
|
||||||
|
elseif ($code >= 400) {
|
||||||
|
throw new \Exception(sprintf("HTTP code received : $code with page content : %s", $exec));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
return $exec;
|
return $exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,11 +44,11 @@ class TaskHandler {
|
||||||
$this->dataManipulator->run($post);
|
$this->dataManipulator->run($post);
|
||||||
}
|
}
|
||||||
|
|
||||||
$post['data'] = json_encode($post['data'] ?? null);
|
$post['data'] = json_encode($post['data'] ?? null, JSON_INVALID_UTF8_IGNORE);
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hash(array $content) : string
|
public function hash(array $content) : string
|
||||||
{
|
{
|
||||||
return md5(implode('-', [ $content['file'], $content['line'], $content['title'] ]));
|
return md5(implode('-', [ $content['file'], $content['line'], $content['title'] ]));
|
||||||
|
|
Loading…
Reference in New Issue