*/
namespace Friendica\Core;
-use Friendica\BaseObject;
use Friendica\Core;
use Friendica\Database\DBA;
+use Friendica\DI;
use Friendica\Model\Process;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
*/
public static function processQueue($run_cron = true)
{
- $a = \get_app();
-
// Ensure that all "strtotime" operations do run timezone independent
date_default_timezone_set('UTC');
self::$up_start = microtime(true);
// At first check the maximum load. We shouldn't continue with a high load
- if ($a->isMaxLoadReached()) {
+ if (DI::process()->isMaxLoadReached()) {
Logger::log('Pre check: maximum load reached, quitting.', Logger::DEBUG);
return;
}
}
// Do we have too few memory?
- if ($a->isMinMemoryReached()) {
+ if (DI::process()->isMinMemoryReached()) {
Logger::log('Pre check: Memory limit reached, quitting.', Logger::DEBUG);
return;
}
}
// Possibly there are too much database processes that block the system
- if ($a->isMaxProcessesReached()) {
+ if (DI::process()->isMaxProcessesReached()) {
Logger::log('Pre check: maximum processes reached, quitting.', Logger::DEBUG);
return;
}
}
// Check free memory
- if ($a->isMinMemoryReached()) {
+ if (DI::process()->isMinMemoryReached()) {
Logger::log('Memory limit reached, quitting.', Logger::DEBUG);
Lock::release('worker');
return;
*/
public static function execute($queue)
{
- $a = \get_app();
-
$mypid = getmypid();
// Quit when in maintenance
}
// Constantly check the number of parallel database processes
- if ($a->isMaxProcessesReached()) {
+ if (DI::process()->isMaxProcessesReached()) {
Logger::log("Max processes reached for process ".$mypid, Logger::DEBUG);
return false;
}
*/
private static function execFunction($queue, $funcname, $argv, $method_call)
{
- $a = \get_app();
+ $a = DI::app();
$argc = count($argv);
// We use the callstack here to analyze the performance of executed worker entries.
// For this reason the variables have to be initialized.
- $a->getProfiler()->reset();
+ DI::profiler()->reset();
$a->queue = $queue;
Logger::info('Process done.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration, 3)]);
- $a->getProfiler()->saveLog($a->getLogger(), "ID " . $queue["id"] . ": " . $funcname);
+ DI::profiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname);
$cooldown = Config::get("system", "worker_cooldown", 0);
return;
}
- $url = System::baseUrl()."/worker";
+ $url = DI::baseUrl() . '/worker';
Network::fetchUrl($url, false, 1);
}
$args = ['no_cron' => !$do_cron];
- $a = get_app();
- $process = new Core\Process($a->getLogger(), $a->getMode(), $a->getConfig(), $a->getBasePath());
+ $a = DI::app();
+ $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), $a->getBasePath());
$process->run($command, $args);
// after spawning we have to remove the flag.
$priority = PRIORITY_MEDIUM;
// Don't fork from frontend tasks by default
- $dont_fork = Config::get("system", "worker_dont_fork", false) || !\get_app()->getMode()->isBackend();
+ $dont_fork = Config::get("system", "worker_dont_fork", false) || !DI::mode()->isBackend();
$created = DateTimeFormat::utcNow();
$force_priority = false;
*/
public static function defer()
{
- if (empty(BaseObject::getApp()->queue)) {
+ if (empty(DI::app()->queue)) {
return false;
}
- $queue = BaseObject::getApp()->queue;
+ $queue = DI::app()->queue;
$retrial = $queue['retrial'];
$id = $queue['id'];