Removed debugging from ADB Rimo Import Broker
This commit is contained in:
50
scripts/adb-rimo-import/adb-rimo-import-broker.php
Normal file → Executable file
50
scripts/adb-rimo-import/adb-rimo-import-broker.php
Normal file → Executable file
@@ -5,10 +5,19 @@ if (PHP_SAPI !== 'cli') {
|
||||
die("This program can only be run on the command line.\n");
|
||||
}
|
||||
|
||||
posix_setrlimit(POSIX_RLIMIT_FSIZE, 1024*1024*1024, 1024*1024*1024); // Limit max filesize to 1 GB
|
||||
posix_setrlimit(POSIX_RLIMIT_FSIZE, 1024*1024*1024*5, 1024*1024*1024*5); // Limit max filesize to 5 GB
|
||||
|
||||
if(pidislocked()) {
|
||||
_debug_log("ADB Rimo Import Broker läuft bereits (pidfile vorhanden)");
|
||||
die("ADB Rimo Import Broker läuft bereits (pidfile vorhanden)");
|
||||
}
|
||||
if(!lockpid()) {
|
||||
die("Error creating lock file!\n");
|
||||
}
|
||||
|
||||
require("../../config/config.php");
|
||||
|
||||
$debug_log = false;
|
||||
|
||||
/*
|
||||
* Redirecting output so rlimit for filesize works
|
||||
@@ -82,15 +91,6 @@ pcntl_signal(SIGTERM, 'signalHandler');
|
||||
$forkcount = 0;
|
||||
$childpids = [];
|
||||
|
||||
if(pidislocked()) {
|
||||
echo "ADB Rimo Import Broker läuft bereits (pidfile vorhanden)\n";
|
||||
exit;
|
||||
}
|
||||
if(!lockpid()) {
|
||||
$log->error(__FILE__.": Error creating lock file!");
|
||||
die("Error creating lock file!\n");
|
||||
}
|
||||
|
||||
$max_processes = 10;
|
||||
|
||||
$all_pids = [];
|
||||
@@ -146,14 +146,14 @@ while(1) {
|
||||
foreach($processes as $key => $proc) {
|
||||
if($proc["pid"]) {
|
||||
// process is running already, nothing to do here
|
||||
echo "[parent] ".$proc["cluster_id"]." pid exists (".$proc["pid"].")\n";
|
||||
_debug_log("[parent] ".$proc["cluster_id"]." pid exists (".$proc["pid"].")");
|
||||
continue;
|
||||
}
|
||||
|
||||
$cluster_id = $proc["cluster_id"];
|
||||
|
||||
if(isset($childpids[$cluster_id])) {
|
||||
echo "[parent] job for ".$proc["cluster_id"]." exists\n";
|
||||
_debug_log("[parent] job for ".$proc["cluster_id"]." exists");
|
||||
//echo "cannot start new $taskname job, because another one is running already\n";
|
||||
continue;
|
||||
}
|
||||
@@ -167,13 +167,13 @@ while(1) {
|
||||
}
|
||||
|
||||
if(count($all_pids) >= $max_processes) {
|
||||
echo "[parent] max processes reached. Currently ".count($all_pids)." running processes.\n";
|
||||
_debug_log("[parent] max processes reached. Currently ".count($all_pids)." running processes.");
|
||||
$fork_delay = 10;
|
||||
sleep(1);
|
||||
break;
|
||||
}
|
||||
|
||||
echo "[parent] forking for $cluster_id\n";
|
||||
_debug_log("[parent] forking for $cluster_id");
|
||||
$pid = pcntl_fork();
|
||||
|
||||
$fork_delay = 10;
|
||||
@@ -227,7 +227,7 @@ while(1) {
|
||||
$status = false;
|
||||
$return_pid = pcntl_wait($status, WNOHANG);
|
||||
if($return_pid) {
|
||||
echo "child $return_pid returned\n";
|
||||
_debug_log("child $return_pid returned");
|
||||
$pid_proc = $all_pids[$return_pid];
|
||||
$pid_task = $pid_proc["cluster_id"];
|
||||
$childpids[$pid_task] = null;
|
||||
@@ -321,18 +321,6 @@ function signalHandler($sig) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function client_log($pid, $text, $severity = "notice") {
|
||||
global $log;
|
||||
global $is_daemon;
|
||||
|
||||
if($is_daemon) {
|
||||
echo "[".date('Y-m-d H:i:s')."] [$pid] $text\n";
|
||||
}
|
||||
$log->$severity($text);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function pidislocked() {
|
||||
$pidfile = __DIR__."/.adb-rimo-import-broker.lock";
|
||||
if(file_exists($pidfile)) {
|
||||
@@ -357,4 +345,12 @@ function unlockpid() {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _debug_log($text) {
|
||||
global $debug_log;
|
||||
|
||||
if($debug_log) {
|
||||
echo "$text\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user