method runTask documentation in bbn\Cron\Runner

function(array $cfg) { if (X::hasProps($cfg, ['id', 'file', 'log_file'], true) && $this->check()) { if (!defined('BBN_EXTERNAL_USER_ID') && defined('BBN_EXTERNAL_USER_EMAIL')) { define('BBN_EXTERNAL_USER_ID', $this->db->selectOne('bbn_users', 'id', ['email' => BBN_EXTERNAL_USER_EMAIL])); } if ($this->cron->getManager()->start($cfg['id'])) { $log = [ 'start' => date('Y-m-d H:i:s'), 'file' => $cfg['file'], 'pid' => getmypid() ]; $day = date('d'); $month = date('m'); $bits = X::split($cfg['log_file'], '/'); $path = X::join(array_slice($bits, -5), '/'); $path_elements = array_splice($bits, -5, 3); //$path_bits = array_splice($bits, -5); //$path = X::join($path_bits, '/'); $json_file = X::dirname(X::dirname(X::dirname($cfg['log_file']))).'/'.X::join($path_elements, '-').'.json'; array_pop($path_elements); $month_file = X::dirname(X::dirname($json_file)).'/'.X::join($path_elements, '-').'.json'; array_pop($path_elements); $year_file = X::dirname(X::dirname($month_file)).'/'.X::join($path_elements, '-').'.json'; if (!is_file($json_file)) { $logs = []; } elseif ($logs = file_get_contents($json_file)) { try { $logs = json_decode($logs, true, 512, JSON_THROW_ON_ERROR); } catch (\Exception $e) { $logs = []; } } if (is_array($logs)) { $idx = count($logs); } $logs[] = $log; file_put_contents($json_file, Json_encode($logs, JSON_PRETTY_PRINT)); $this->timer->start($cfg['file']); $this->controller->reroute($cfg['file']); $this->controller->process(); $logs[$idx]['duration'] = $this->timer->stop($cfg['file']); $content = file_get_contents($cfg['log_file']); if (empty($content)) { unlink($cfg['log_file']); $logs[$idx]['content'] = false; } else { $logs[$idx]['content'] = $path; } $logs[$idx]['end'] = date('Y-m-d H:i:s'); file_put_contents($json_file, Json_encode($logs, JSON_PRETTY_PRINT)); $default_month_data = [ 'total' => 0, 'content' => 0, 'first' => $logs[$idx]['start'], 'last' => null, 'dates' => [], 'duration' => 0, 'duration_content' => 0 ]; if (!is_file($month_file)) { $mlogs = $default_month_data; } else { $mlogs = json_decode(file_get_contents($month_file), true) ?? $default_month_data; } $mlogs['total']++; $mlogs['duration'] += $logs[$idx]['duration']; if (!empty($content)) { $mlogs['content']++; $mlogs['duration_content'] += $logs[$idx]['duration']; } $mlogs['last'] = $logs[$idx]['start']; if (!in_array($day, $mlogs['dates'])) { $mlogs['dates'][] = $day; } file_put_contents($month_file, Json_encode($mlogs, JSON_PRETTY_PRINT)); $default_year_data = [ 'total' => 0, 'content' => 0, 'first' => $logs[$idx]['start'], 'last' => null, 'month' => [], 'duration' => 0, 'duration_content' => 0 ];; if (!is_file($year_file)) { $ylogs = $default_year_data; } else { $ylogs = json_decode(file_get_contents($year_file), true) ?? $default_year_data; } $ylogs['total']++; $ylogs['duration'] += $logs[$idx]['duration']; if (!empty($content)) { $ylogs['content']++; $ylogs['duration_content'] += $logs[$idx]['duration']; } $ylogs['last'] = $logs[$idx]['start']; if (!in_array($month, $ylogs['month'])) { $ylogs['month'][] = $month; } file_put_contents($year_file, Json_encode($ylogs, JSON_PRETTY_PRINT)); } } exit(); }

BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.