40 lines
1.6 KiB
PHP
40 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Handles the result of cron job execution, including error handling.
|
|
*
|
|
* @param int $result Exit code from the sandbox execution (0 for success, non-zero for failure).
|
|
* @param string $stdout Captured standard output from the execution (JSON encoded data).
|
|
* @param string $stderr Captured standard error from the execution (error message if any).
|
|
* @param array $cronJobId The id of executed Cron Job.
|
|
*/
|
|
function handleCronJobExecutionResult($result, $stdout, $stderr, $cronJobId) {
|
|
|
|
// 1. HANDLE FAILURE (Exit Code is not 0)
|
|
if ($result !== 0) {
|
|
// Update table with the error message from stderr
|
|
updateCronError($cronJobId, $stderr);
|
|
|
|
// Notify via Telegram (assuming a helper function exists)
|
|
sendTelegramMessage("Cron Job #$cronJobId Failed: " . $stderr,"DatabaseGroup");
|
|
}
|
|
// 2. HANDLE SUCCESS
|
|
else {
|
|
// Decode the output
|
|
$outputData = json_decode($stdout, true);
|
|
|
|
// If stdout exists but isn't valid JSON, treat it as an error
|
|
if (!empty($stdout) && $outputData === null) {
|
|
updateCronError($cronJobId, 'Invalid JSON output from sandboxed execution.');
|
|
return;
|
|
}
|
|
|
|
// Unlike Triggers, Cron Jobs don't usually compare $originalRow vs $newRow.
|
|
// We simply mark the job as clean/successful.
|
|
clearCronError($cronJobId);
|
|
|
|
// Optional: If your Cron Jobs are supposed to save data returned in $stdout,
|
|
// you would call that save function here.
|
|
// saveCronOutput($cronJobId, $outputData);
|
|
}
|
|
}
|