]> git.mxchange.org Git - friendica.git/commitdiff
Check for bad worker priorities
authorMichael <heluecht@pirati.ca>
Tue, 8 Dec 2020 21:58:32 +0000 (21:58 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 8 Dec 2020 21:58:32 +0000 (21:58 +0000)
boot.php
src/Core/Worker.php
src/Model/Item.php
src/Protocol/Feed.php
src/Worker/DelayedPublish.php

index 6674c6fc7cb34b518d099d3c8bd2926bf1e2c37b..504f997d9ff3aa76a12baa0892b2210559ddebbd 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -201,6 +201,7 @@ define('PRIORITY_HIGH',       20);
 define('PRIORITY_MEDIUM',     30);
 define('PRIORITY_LOW',        40);
 define('PRIORITY_NEGLIGIBLE', 50);
+define('PRIORITIES', [PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE]);
 /* @}*/
 
 /**
index 4f455277641f9b6ca43f1547b02685d814b20e1d..4fcca35f12ff69caad6a74ee191902024d5adb20 100644 (file)
@@ -421,6 +421,11 @@ class Worker
                // For this reason the variables have to be initialized.
                DI::profiler()->reset();
 
+               if (!in_array($queue['priority'], PRIORITIES)) {
+                       Logger::warning('Invalid period', ['queue' => $queue, 'callstack' => System::callstack(20)]);
+                       $queue['priority'] = PRIORITY_MEDIUM;
+               }
+
                $a->queue = $queue;
 
                $up_duration = microtime(true) - self::$up_start;
@@ -1264,6 +1269,11 @@ class Worker
                $found = DBA::exists('workerqueue', ['command' => $command, 'parameter' => $parameters, 'done' => false]);
                $added = false;
 
+               if (!in_array($priority, PRIORITIES)) {
+                       Logger::warning('Invalid period', ['priority' => $priority, 'command' => $command, 'callstack' => System::callstack(20)]);
+                       $priority = PRIORITY_MEDIUM;
+               }
+
                // Quit if there was a database error - a precaution for the update process to 3.5.3
                if (DBA::errorNo() != 0) {
                        return false;
index d41e84c5b9f44c5e6ff0b1d61cb15c9d542c56a3..15ea69eeb94df1a40d0c770698a3aef767a3f4d5 100644 (file)
@@ -1568,7 +1568,7 @@ class Item
                        $item['network'] = Protocol::DFRN;
                        $item['protocol'] = Conversation::PARCEL_DIRECT;
 
-                       if (is_int($notify)) {
+                       if (in_array($notify, PRIORITIES)) {
                                $priority = $notify;
                        }
                } else {
@@ -2912,7 +2912,7 @@ class Item
                $_SESSION["authenticated"] = true;
                $_SESSION["uid"] = $contact['uid'];
 
-               return $result;
+               return (bool)$result;
        }
 
        /**
index fa568b4c3c14dcf6ecec652c45a64f5b6c346495..a2e9daaa036ab31826aa4ac82991ec72e5cd173b 100644 (file)
@@ -623,7 +623,7 @@ class Feed
                                                'taglist' => $taglist, 'attachments' => $attachments];
                                }
                        } else {
-                               Logger::info('Post already crated or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item["uri"]]);
+                               Logger::info('Post already created or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item["uri"]]);
                        }
                }
 
index beffb22e303da3c4f863d71c9a3dfee96b94ce68..db37ba306789cfa9ee986cf1b70405e368163703 100644 (file)
@@ -22,9 +22,7 @@
 namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
-use Friendica\Model\Item;
 use Friendica\Model\Post;
-use Friendica\Model\Tag;
 
 class DelayedPublish
 {
@@ -40,6 +38,6 @@ class DelayedPublish
        public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [])
        {
                $id = Post\Delayed::publish($item, $notify, $taglist, $attachments);
-               Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]);
+               Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id'], 'notify' => $notify]);
        }
 }