CoolCMS API

CronJobHttpCaller
in package

FinalYes

Calls one cron job over HTTP on the application's own address — the same path a hosting cron would use, with the same token, so no job has to be rewritten.

Never throws: a refused connection, a timeout or a 5xx is a CronJobCallResult with status error. IMPORTANT: the token is part of the URL, so it is stripped from everything that leaves this class (the shortened response and any transport error text) — it must never reach the DB or a log.

Table of Contents

Constants

MAX_RESPONSE_LENGTH  : int = 500
Longest stored response text.

Properties

$httpClient  : ClientInterface

Methods

__construct()  : mixed
call()  : CronJobCallResult
resolveStatus()  : string
`ok` for 2xx (a JSON `{"status":"error"}` still counts as error), `skipped` when the job's own lock says another run is in progress, `error` otherwise.
shorten()  : string
Plain text, the token and URL query values removed, at most {@see MAX_RESPONSE_LENGTH} characters.
elapsedMs()  : int

Constants

MAX_RESPONSE_LENGTH

Longest stored response text.

public int MAX_RESPONSE_LENGTH = 500

Properties

Methods

__construct()

public __construct([ClientInterface|null $httpClient = null ]) : mixed
Parameters
$httpClient : ClientInterface|null = null

call()

public call(string $baseUrl, string $path, array<string, string> $query, string $token, float $timeout) : CronJobCallResult
Parameters
$baseUrl : string

scheme + host (+ port) of the current request, without a trailing slash

$path : string
$query : array<string, string>

fixed query parameters of the job

$token : string
$timeout : float

seconds the call may take (the rest of the scheduler time budget)

Return values
CronJobCallResult

resolveStatus()

`ok` for 2xx (a JSON `{"status":"error"}` still counts as error), `skipped` when the job's own lock says another run is in progress, `error` otherwise.

public static resolveStatus(int $httpCode, string $body) : string
Parameters
$httpCode : int
$body : string
Return values
string

shorten()

Plain text, the token and URL query values removed, at most {@see MAX_RESPONSE_LENGTH} characters.

public static shorten(string $text, string $token) : string
Parameters
$text : string
$token : string
Return values
string

elapsedMs()

private static elapsedMs(float $started) : int
Parameters
$started : float
Return values
int
On this page

Search results