Lock now can use the memcache as well

This commit is contained in:
Michael 2017-06-04 15:59:20 +00:00
parent d2cb87a200
commit bca5776e9c
2 changed files with 104 additions and 12 deletions

View file

@ -2,6 +2,7 @@
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Util\Lock;
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
$directory = dirname($_SERVER["argv"][0]);
@ -19,16 +20,12 @@ require_once("boot.php");
function poller_run($argv, $argc){
global $a, $db;
if (is_null($a)) {
$a = new App(dirname(__DIR__));
}
$a = new App(dirname(__DIR__));
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
Config::load();
@ -41,6 +38,10 @@ function poller_run($argv, $argc){
load_hooks();
if (($argc <= 1) OR ($argv[1] != "no_cron")) {
poller_run_cron();
}
$a->start_process();
if ($a->min_memory_reached()) {
@ -55,11 +56,11 @@ function poller_run($argv, $argc){
return;
}
if(($argc <= 1) OR ($argv[1] != "no_cron")) {
poller_run_cron();
if ($a->max_processes_reached()) {
return;
}
if ($a->max_processes_reached()) {
if (!Lock::set('poller_worker')) {
return;
}
@ -69,6 +70,8 @@ function poller_run($argv, $argc){
return;
}
Lock::remove('poller_worker');
$starttime = time();
while ($r = poller_worker_process()) {
@ -83,12 +86,18 @@ function poller_run($argv, $argc){
return;
}
if (!Lock::set('poller_worker')) {
return;
}
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers()) {
logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
return;
}
Lock::remove('poller_worker');
if (!poller_execute($r[0])) {
logger('Process execution failed, quitting.', LOGGER_DEBUG);
return;
@ -724,6 +733,8 @@ function poller_run_cron() {
if (array_search(__file__,get_included_files())===0){
poller_run($_SERVER["argv"],$_SERVER["argc"]);
Lock::removeAll();
poller_unclaim_process();
get_app()->end_process();