Skip to content

Commit

Permalink
- set max_execution_time for CLI Cronjob script, closed #636
Browse files Browse the repository at this point in the history
  • Loading branch information
exodus4d committed Jun 17, 2018
1 parent 7a552f3 commit f9e1fee
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
27 changes: 27 additions & 0 deletions app/main/cron/abstractcron.php
Original file line number Diff line number Diff line change
@@ -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);
}

}
3 changes: 2 additions & 1 deletion app/main/cron/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

Expand All @@ -34,6 +34,7 @@ protected function getExpireMaxTime(\Base $f3): int {
* @param \Base $f3
*/
function deleteExpiredData(\Base $f3){
$this->setMaxExecutionTime();
$time_start = microtime(true);

// cache dir (dir is recursively searched...)
Expand Down
4 changes: 2 additions & 2 deletions app/main/cron/ccpsystemsupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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)';

Expand All @@ -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();
Expand Down Expand Up @@ -72,6 +71,7 @@ private function prepareSystemLogTables(){
* @param \Base $f3
*/
function importSystemData($f3){
$this->setMaxExecutionTime();

// prepare system jump log table ------------------------------------------------------------------------------
$time_start = microtime(true);
Expand Down
8 changes: 5 additions & 3 deletions app/main/cron/characterupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Model;


class CharacterUpdate {
class CharacterUpdate extends AbstractCron {

/**
* default character_log time until a log entry get re-checked by cronjob
Expand Down Expand Up @@ -41,6 +41,7 @@ protected function getCharacterLogInactiveTime(\Base $f3){
* @throws \Exception
*/
function deleteLogData(\Base $f3){
$this->setMaxExecutionTime();
DB\Database::instance()->getDB('PF');
$logInactiveTime = $this->getCharacterLogInactiveTime($f3);

Expand Down Expand Up @@ -84,6 +85,7 @@ function deleteLogData(\Base $f3){
* @throws \Exception
*/
function cleanUpCharacterData(\Base $f3){
$this->setMaxExecutionTime();
DB\Database::instance()->getDB('PF');

/**
Expand All @@ -96,7 +98,6 @@ function cleanUpCharacterData(\Base $f3){
':active' => 1
]);


if(is_object($characters)){
foreach($characters as $character){
/**
Expand All @@ -115,7 +116,8 @@ function cleanUpCharacterData(\Base $f3){
* @param \Base $f3
* @throws \Exception
*/
function deleteAuthenticationData($f3){
function deleteAuthenticationData(\Base $f3){
$this->setMaxExecutionTime();
DB\Database::instance()->getDB('PF');

/**
Expand Down
7 changes: 6 additions & 1 deletion app/main/cron/mapupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use lib\Config;
use Model;

class MapUpdate {
class MapUpdate extends AbstractCron {

const LOG_TEXT_MAPS = '%s (%d maps)';

Expand All @@ -25,6 +25,7 @@ class MapUpdate {
* @throws \Exception\PathfinderException
*/
function deactivateMapData(\Base $f3){
$this->setMaxExecutionTime();
$privateMapLifetime = (int)Config::getMapsDefaultConfig('private.lifetime');

if($privateMapLifetime > 0){
Expand All @@ -49,6 +50,7 @@ function deactivateMapData(\Base $f3){
* @throws \Exception
*/
function deleteMapData(\Base $f3){
$this->setMaxExecutionTime();
$pfDB = DB\Database::instance()->getDB('PF');
$deletedMapsCount = 0;

Expand Down Expand Up @@ -87,6 +89,7 @@ function deleteMapData(\Base $f3){
* @throws \Exception
*/
function deleteEolConnections(\Base $f3){
$this->setMaxExecutionTime();
$eolExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_CONNECTIONS_EOL');

if($eolExpire > 0){
Expand Down Expand Up @@ -131,6 +134,7 @@ function deleteEolConnections(\Base $f3){
* @throws \Exception
*/
function deleteExpiredConnections(\Base $f3){
$this->setMaxExecutionTime();
$whExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_CONNECTIONS_WH');

if($whExpire > 0){
Expand Down Expand Up @@ -176,6 +180,7 @@ function deleteExpiredConnections(\Base $f3){
* @param \Base $f3
*/
function deleteSignatures(\Base $f3){
$this->setMaxExecutionTime();
$signatureExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_SIGNATURES');

if($signatureExpire > 0){
Expand Down
4 changes: 3 additions & 1 deletion app/main/cron/statisticsupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace cron;
use DB;

class StatisticsUpdate {
class StatisticsUpdate extends AbstractCron {

const LOG_TEXT_STATISTICS = '%s (%d rows)';

Expand All @@ -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;
Expand Down

0 comments on commit f9e1fee

Please sign in to comment.