- WIP on Task scheduling interface

This commit is contained in:
Dave M. 2024-04-22 13:55:36 +00:00
parent 586f2344df
commit 5a737c06c4
4 changed files with 26 additions and 9 deletions

View File

@ -45,7 +45,7 @@ namespace Negundo\Client {
namespace {
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) {
$sent = $instance->newReport($message, $title, $data);

10
src/Task/StatusEnum.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace Negundo\Client\Task;
enum StatusEnum : string
{
case Completed = "completed";
case Failed = "failed";
case Warning = "warning";
}

View File

@ -26,11 +26,18 @@ class Curl implements TransportInterface {
$exec = curl_exec($ch);
if ( ( false === $exec ) && $this->throwErrors ) {
$errno = curl_errno($ch);
curl_close($ch);
$code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
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);

View File

@ -44,7 +44,7 @@ class TaskHandler {
$this->dataManipulator->run($post);
}
$post['data'] = json_encode($post['data'] ?? null);
$post['data'] = json_encode($post['data'] ?? null, JSON_INVALID_UTF8_IGNORE);
return $post;
}