Move process functions to Model\Process

- Add start|endProcess functions to Core\Worker
This commit is contained in:
Hypolite Petovan 2018-01-15 19:08:28 -05:00
parent b699637ab7
commit 78ac7afe9c
5 changed files with 104 additions and 56 deletions

View file

@ -2,20 +2,17 @@
namespace Friendica;
use Friendica\Core\System;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use dba;
use Friendica\Core\System;
use Detection\MobileDetect;
use Exception;
require_once 'boot.php';
require_once 'include/dba.php';
require_once 'include/text.php';
/**
*
@ -695,49 +692,6 @@ class App {
$this->callstack[$value][$callstack] += (float) $duration;
}
/**
* @brief Log active processes into the "process" table
*/
function start_process() {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
$command = basename($trace[0]['file']);
$this->remove_inactive_processes();
dba::transaction();
$r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
if (!DBM::is_result($r)) {
dba::insert('process', ['pid' => getmypid(), 'command' => $command, 'created' => datetime_convert()]);
}
dba::commit();
}
/**
* @brief Remove inactive processes
*/
function remove_inactive_processes() {
dba::transaction();
$r = q('SELECT `pid` FROM `process`');
if (DBM::is_result($r)) {
foreach ($r AS $process) {
if (!posix_kill($process['pid'], 0)) {
dba::delete('process', ['pid' => $process['pid']]);
}
}
}
dba::commit();
}
/**
* @brief Remove the active process from the "process" table
*/
function end_process() {
dba::delete('process', ['pid' => getmypid()]);
}
function get_useragent() {
return
FRIENDICA_PLATFORM . " '" .