$ps[2], 'file' => $dir.'/'.$jf, 'software' => $ps[0], 'instance' => $ps[1], 'time' => intval($ps[3]), ]; } foreach ($jobs as $job) { $ms = time() - filemtime($job->file); $sql = file_get_contents($job->file); if ($ms < $job->time) continue; logi("Processing job: {$job->id}, software={$job->software}, instance={$job->instance}"); $ok = false; switch ($job->software) { case 'mastodon': $pg = new PgDatabase($job->software, $job->instance); 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) { logi("Job done: {$job->id}"); touch($job->file); } } } run__cronjobs_db(); // //////////////////////////////// /////////////////////////////// // CRONJOBS for caching cleanup // function run__cronjobs_cache_cleanup() { $cache_dir = $GLOBALS['appconf']['data_dir'].'/cache'; if (!file_exists($cache_dir)) return; foreach (scandir($cache_dir) as $fl) { if (in_array($fl, ['.','..'])) continue; $ps = explode(',',$fl); if ($ps[1] !== 'ondemand') continue; $time = intval($ps[2]); $mtime = filemtime($cache_dir.'/'.$fl); if (time() - $mtime >= $time) { logi('CACHE-CLEANUP remove old file: '.$fl); unlink($cache_dir.'/'.$fl); } } } run__cronjobs_cache_cleanup(); // /////////////////////////////// $ms_total = time() - $time_start; logi("Cron has finished in {$ms_total} seconds"); end_cronjobs();