mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-16 20:05:14 +02:00
The function to check for maxload and the lockfile is centralized
This commit is contained in:
parent
ec9c9f0be7
commit
beb2346cfc
10 changed files with 66 additions and 172 deletions
37
boot.php
37
boot.php
|
@ -30,7 +30,7 @@ require_once('include/cache.php');
|
|||
require_once('library/Mobile_Detect/Mobile_Detect.php');
|
||||
require_once('include/features.php');
|
||||
require_once('include/identity.php');
|
||||
|
||||
require_once('include/pidfile.php');
|
||||
require_once('update.php');
|
||||
require_once('include/dbstructure.php');
|
||||
|
||||
|
@ -1098,6 +1098,41 @@ class App {
|
|||
return($this->is_friendica_app);
|
||||
}
|
||||
|
||||
function maxload_reached() {
|
||||
|
||||
$maxsysload = intval(get_config('system', 'maxloadavg'));
|
||||
if ($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if ($load) {
|
||||
if (intval($load) > $maxsysload) {
|
||||
logger('system: load '.$load.' too high.');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_already_running($task, $taskname, $timeout = 540) {
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, $taskname);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("Already running");
|
||||
if ($pidfile->running_time() > $timeout) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
// Calling a new instance
|
||||
if ($task != "")
|
||||
proc_run('php', $task);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue