- set max_execution_time for CLI Cronjob script, closed #636

This commit is contained in:
Mark Friedrich
2018-06-17 12:25:38 +02:00
parent 7a552f3bab
commit f9e1fee619
6 changed files with 45 additions and 8 deletions

View 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);
}
}

View File

@@ -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...)

View File

@@ -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);

View File

@@ -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');
/**

View File

@@ -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){

View File

@@ -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;