Various improvements in cron.php

This commit is contained in:
Bofh 2022-12-03 17:03:23 +01:00
parent eb180cdcdf
commit adeccbc4f1
2 changed files with 16 additions and 8 deletions

View File

@ -36,8 +36,10 @@ function apiresult($data, $code=200) {
$GLOBALS['api_data'] = $data;
return false;
}
if ($code !== 200) http_response_code($code);
header('Content-Type: application/json');
if (isset($_SERVER['REQUEST_URI'])) {
if ($code !== 200) http_response_code($code);
header('Content-Type: application/json');
}
if (gettype($data) !== 'string')
echo json_encode($data);
else echo $data;

View File

@ -23,6 +23,7 @@ if (!file_exists($GLOBALS['_crondir'])) {
mkdir($GLOBALS['_crondir']);
end_cronjobs();
}
$time_start = time();
//
////////////////
@ -59,20 +60,25 @@ function run__cronjobs_db() {
switch ($job->software) {
case 'mastodon':
$pg = new PgDatabase($job->software, $job->instance);
$result = $pg->fetch_all($sql);
content_cache__put($job->software.$job->instance.$sql, 'always,'.$job->time, $result);
$pg->close();
$ok = true;
if ($pg->is_ok()) {
$result = $pg->fetch_all($sql);
content_cache__put($job->software.$job->instance.$sql, 'always,'.$job->time, $result);
$pg->close();
$ok = true;
}
break;
}
if ($ok)
if ($ok) {
logi("Job done: {$job->id}");
touch($job->file);
}
}
}
run__cronjobs_db();
//
////////////////////////////////
logi('Cron has finished!');
$ms_total = time() - $time_start;
logi("Cron has finished in {$ms_total} seconds");
end_cronjobs();