- set max_execution_time for CLI Cronjob script, closed #636
This commit is contained in:
27
app/main/cron/abstractcron.php
Normal file
27
app/main/cron/abstractcron.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: exodu
|
||||
* Date: 17.06.2018
|
||||
* Time: 12:13
|
||||
*/
|
||||
|
||||
namespace cron;
|
||||
|
||||
abstract class AbstractCron {
|
||||
|
||||
// default max_execution_time for cronJobs
|
||||
// -> should be less then execution period
|
||||
const DEFAULT_MAX_EXECUTION_TIME = 50;
|
||||
|
||||
/**
|
||||
* set max execution time for cronjobs
|
||||
* -> Default CLI execution time is "0" -> infinite!
|
||||
* php.ini settings are ignored! http://php.net/manual/en/info.configuration.php#ini.max-execution-time
|
||||
* @param int $time
|
||||
*/
|
||||
protected function setMaxExecutionTime(int $time = self::DEFAULT_MAX_EXECUTION_TIME){
|
||||
ini_set('max_execution_time', $time);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace cron;
|
||||
|
||||
use data\filesystem\Search;
|
||||
|
||||
class Cache {
|
||||
class Cache extends AbstractCron {
|
||||
|
||||
const LOG_TEXT = '%s [%\'_10s] files, size [%\'_10s] byte, not writable [%\'_10s] files, errors [%\'_10s], exec (%.3Fs)';
|
||||
|
||||
@@ -34,6 +34,7 @@ class Cache {
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function deleteExpiredData(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
$time_start = microtime(true);
|
||||
|
||||
// cache dir (dir is recursively searched...)
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cron;
|
||||
use Controller;
|
||||
use DB;
|
||||
|
||||
class CcpSystemsUpdate {
|
||||
class CcpSystemsUpdate extends AbstractCron {
|
||||
|
||||
const LOG_TEXT = '%s prepare table (%.3F s), jump (%.3F s), kill (%.3F s), update all (%.3F s)';
|
||||
|
||||
@@ -35,7 +35,6 @@ class CcpSystemsUpdate {
|
||||
* @return array
|
||||
*/
|
||||
private function prepareSystemLogTables(){
|
||||
|
||||
// get information for all systems from CCP DB
|
||||
$systemController = new Controller\Api\System();
|
||||
$systemsData = $systemController->getSystems();
|
||||
@@ -72,6 +71,7 @@ class CcpSystemsUpdate {
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function importSystemData($f3){
|
||||
$this->setMaxExecutionTime();
|
||||
|
||||
// prepare system jump log table ------------------------------------------------------------------------------
|
||||
$time_start = microtime(true);
|
||||
|
||||
@@ -11,7 +11,7 @@ use DB;
|
||||
use Model;
|
||||
|
||||
|
||||
class CharacterUpdate {
|
||||
class CharacterUpdate extends AbstractCron {
|
||||
|
||||
/**
|
||||
* default character_log time until a log entry get re-checked by cronjob
|
||||
@@ -41,6 +41,7 @@ class CharacterUpdate {
|
||||
* @throws \Exception
|
||||
*/
|
||||
function deleteLogData(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
DB\Database::instance()->getDB('PF');
|
||||
$logInactiveTime = $this->getCharacterLogInactiveTime($f3);
|
||||
|
||||
@@ -84,6 +85,7 @@ class CharacterUpdate {
|
||||
* @throws \Exception
|
||||
*/
|
||||
function cleanUpCharacterData(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
DB\Database::instance()->getDB('PF');
|
||||
|
||||
/**
|
||||
@@ -96,7 +98,6 @@ class CharacterUpdate {
|
||||
':active' => 1
|
||||
]);
|
||||
|
||||
|
||||
if(is_object($characters)){
|
||||
foreach($characters as $character){
|
||||
/**
|
||||
@@ -115,7 +116,8 @@ class CharacterUpdate {
|
||||
* @param \Base $f3
|
||||
* @throws \Exception
|
||||
*/
|
||||
function deleteAuthenticationData($f3){
|
||||
function deleteAuthenticationData(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
DB\Database::instance()->getDB('PF');
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ use DB;
|
||||
use lib\Config;
|
||||
use Model;
|
||||
|
||||
class MapUpdate {
|
||||
class MapUpdate extends AbstractCron {
|
||||
|
||||
const LOG_TEXT_MAPS = '%s (%d maps)';
|
||||
|
||||
@@ -25,6 +25,7 @@ class MapUpdate {
|
||||
* @throws \Exception\PathfinderException
|
||||
*/
|
||||
function deactivateMapData(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
$privateMapLifetime = (int)Config::getMapsDefaultConfig('private.lifetime');
|
||||
|
||||
if($privateMapLifetime > 0){
|
||||
@@ -49,6 +50,7 @@ class MapUpdate {
|
||||
* @throws \Exception
|
||||
*/
|
||||
function deleteMapData(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
$pfDB = DB\Database::instance()->getDB('PF');
|
||||
$deletedMapsCount = 0;
|
||||
|
||||
@@ -87,6 +89,7 @@ class MapUpdate {
|
||||
* @throws \Exception
|
||||
*/
|
||||
function deleteEolConnections(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
$eolExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_CONNECTIONS_EOL');
|
||||
|
||||
if($eolExpire > 0){
|
||||
@@ -131,6 +134,7 @@ class MapUpdate {
|
||||
* @throws \Exception
|
||||
*/
|
||||
function deleteExpiredConnections(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
$whExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_CONNECTIONS_WH');
|
||||
|
||||
if($whExpire > 0){
|
||||
@@ -176,6 +180,7 @@ class MapUpdate {
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function deleteSignatures(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
$signatureExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_SIGNATURES');
|
||||
|
||||
if($signatureExpire > 0){
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace cron;
|
||||
use DB;
|
||||
|
||||
class StatisticsUpdate {
|
||||
class StatisticsUpdate extends AbstractCron {
|
||||
|
||||
const LOG_TEXT_STATISTICS = '%s (%d rows)';
|
||||
|
||||
@@ -20,6 +20,8 @@ class StatisticsUpdate {
|
||||
* @param \Base $f3
|
||||
*/
|
||||
function deleteStatisticsData(\Base $f3){
|
||||
$this->setMaxExecutionTime();
|
||||
|
||||
$currentYear = (int)date('o');
|
||||
$currentWeek = (int)date('W');
|
||||
$expiredYear = $currentYear - 1;
|
||||
|
||||
Reference in New Issue
Block a user