* @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function processQueue($run_cron, Process $process)
+ public static function processQueue(bool $run_cron, Process $process)
{
self::$up_start = microtime(true);
*
* @return boolean
*/
- public static function isReady()
+ public static function isReady(): bool
{
// Count active workers and compare them with a maximum value that depends on the load
if (self::tooMuchWorkers()) {
* @return boolean Returns "true" if tasks are existing
* @throws \Exception
*/
- public static function entriesExists()
+ public static function entriesExists(): bool
{
$stamp = (float)microtime(true);
$exists = DBA::exists('workerqueue', ["NOT `done` AND `pid` = 0 AND `next_try` < ?", DateTimeFormat::utcNow()]);
* @return integer Number of deferred entries in the worker queue
* @throws \Exception
*/
- private static function deferredEntries()
+ private static function deferredEntries(): int
{
$stamp = (float)microtime(true);
$count = DBA::count('workerqueue', ["NOT `done` AND `pid` = 0 AND `retrial` > ?", 0]);
* @return integer Number of non executed entries in the worker queue
* @throws \Exception
*/
- private static function totalEntries()
+ private static function totalEntries(): int
{
$stamp = (float)microtime(true);
$count = DBA::count('workerqueue', ['done' => false, 'pid' => 0]);
* @return integer Number of active worker processes
* @throws \Exception
*/
- private static function highestPriority()
+ private static function highestPriority(): int
{
$stamp = (float)microtime(true);
$condition = ["`pid` = 0 AND NOT `done` AND `next_try` < ?", DateTimeFormat::utcNow()];
* @return integer Is there a process running with that priority?
* @throws \Exception
*/
- private static function processWithPriorityActive($priority)
+ private static function processWithPriorityActive(int $priority): int
{
$condition = ["`priority` <= ? AND `pid` != 0 AND NOT `done`", $priority];
return DBA::exists('workerqueue', $condition);
* @param mixed $file
* @return bool
*/
- private static function validateInclude(&$file)
+ private static function validateInclude(&$file): bool
{
$orig_file = $file;
* @return boolean "true" if further processing should be stopped
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function execute($queue)
+ public static function execute(array $queue): bool
{
$mypid = getmypid();
* @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function execFunction($queue, $funcname, $argv, $method_call)
+ private static function execFunction(array $queue, string $funcname, array $argv, bool $method_call)
{
$a = DI::app();
* @return bool Are more than 3/4 of the maximum connections used?
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function maxConnectionsReached()
+ private static function maxConnectionsReached(): bool
{
// Fetch the max value from the config. This is needed when the system cannot detect the correct value by itself.
$max = DI::config()->get("system", "max_connections");
* @return bool Are there too much workers running?
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function tooMuchWorkers()
+ private static function tooMuchWorkers(): bool
{
$queues = DI::config()->get("system", "worker_queues", 10);
* @return integer Number of active worker processes
* @throws \Exception
*/
- private static function activeWorkers()
+ private static function activeWorkers(): int
{
$stamp = (float)microtime(true);
$count = DI::process()->countCommand('Worker.php');
* @return array List of worker process ids
* @throws \Exception
*/
- private static function getWorkerPIDList()
+ private static function getWorkerPIDList(): array
{
$ids = [];
$stamp = (float)microtime(true);
* @return array waiting workerqueue jobs
* @throws \Exception
*/
- private static function getWaitingJobForPID()
+ private static function getWaitingJobForPID(): array
{
$stamp = (float)microtime(true);
$r = DBA::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
* @return array array with next jobs
* @throws \Exception
*/
- private static function nextProcess(int $limit)
+ private static function nextProcess(int $limit): array
{
$priority = self::nextPriority();
if (empty($priority)) {
/**
* Returns the priority of the next workerqueue job
*
- * @return string priority
+ * @return string|bool priority or FALSE on failure
* @throws \Exception
*/
private static function nextPriority()
/**
* Find and claim the next worker process for us
*
- * @return boolean Have we found something?
+ * @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function findWorkerProcesses()
* @return array worker processes
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function workerProcess()
+ public static function workerProcess(): array
{
// There can already be jobs for us in the queue.
$waiting = self::getWaitingJobForPID();
$stamp = (float)microtime(true);
if (!DI::lock()->acquire(self::LOCK_PROCESS)) {
- return false;
+ return [];
}
self::$lock_duration += (microtime(true) - $stamp);
* @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function spawnWorker($do_cron = false)
+ public static function spawnWorker(bool $do_cron = false)
{
if (Worker\Daemon::isMode() && DI::config()->get('system', 'worker_fork')) {
self::forkProcess($do_cron);
return $added;
}
- public static function countWorkersByCommand(string $command)
+ public static function countWorkersByCommand(string $command): int
{
return DBA::count('workerqueue', ['done' => false, 'pid' => 0, 'command' => $command]);
}
* @param integer $max_level maximum retrial level
* @return integer the next retrial level value
*/
- private static function getNextRetrial($queue, $max_level)
+ private static function getNextRetrial(array $queue, int $max_level): int
{
$created = strtotime($queue['created']);
$retrial_time = time() - $created;
/**
* Check if the system is inside the defined maintenance window
*
+ * @param bool $check_last_execution Whether check last execution
* @return boolean
*/
- public static function isInMaintenanceWindow(bool $check_last_execution = false)
+ public static function isInMaintenanceWindow(bool $check_last_execution = false): bool
{
// Calculate the seconds of the start end end of the maintenance window
$start = strtotime(DI::config()->get('system', 'maintenance_start')) % 86400;