From e3caf0f4f556b5d918b4745498e1e3c5cf8dfce8 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 4 Apr 2019 20:51:12 +0000 Subject: [PATCH] Use deferred workers instead of the queue mechanism --- src/Protocol/Diaspora.php | 18 ++++++------------ src/Worker/Delivery.php | 5 +++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 8dfb217ac2..768b4c7b07 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3223,9 +3223,9 @@ class Diaspora if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeader(), "retry-after")))) { if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::TYPE_RELAY)) { - Logger::log("queue message"); - // queue message for redelivery - Queue::add($contact["id"], Protocol::DIASPORA, $envelope, $public_batch, $guid); + Logger::info('defer message', ['log' => $logid, 'guid' => $guid, 'destination' => $dest_url]); + // defer message for redelivery + Worker::defer(); } // The message could not be delivered. We mark the contact as "dead" @@ -3263,13 +3263,12 @@ class Diaspora * @param array $message The message data * @param bool $public_batch Is it a public post? * @param string $guid message guid - * @param bool $spool Should the transmission be spooled or transmitted? * * @return int Result of the transmission * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function buildAndTransmit(array $owner, array $contact, $type, $message, $public_batch = false, $guid = "", $spool = false) + private static function buildAndTransmit(array $owner, array $contact, $type, $message, $public_batch = false, $guid = "") { $msg = self::buildPostXml($type, $message); @@ -3283,12 +3282,7 @@ class Diaspora $envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch); - if ($spool) { - Queue::add($contact['id'], Protocol::DIASPORA, $envelope, $public_batch, $guid); - return true; - } else { - $return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid); - } + $return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid); Logger::log("guid: ".$guid." result ".$return_code, Logger::DEBUG); @@ -4284,7 +4278,7 @@ class Diaspora foreach ($recips as $recip) { Logger::log("Send updated profile data for user ".$uid." to contact ".$recip["id"], Logger::DEBUG); - self::buildAndTransmit($owner, $recip, "profile", $message, false, "", false); + self::buildAndTransmit($owner, $recip, "profile", $message, false); } } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 917a83ccbb..921662a115 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -17,6 +17,7 @@ use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; use Friendica\Util\Strings; use Friendica\Util\Network; +use Friendica\Core\Worker; class Delivery extends BaseObject { @@ -321,8 +322,8 @@ class Delivery extends BaseObject Logger::log('Delivery to ' . $contact['url'] . ' with guid ' . defaults($target_item, 'guid', $target_item['id']) . ' returns ' . $deliver_status); if ($deliver_status < 0) { - Logger::log('Delivery failed: queuing message ' . defaults($target_item, 'guid', $target_item['id'])); - Model\Queue::add($contact['id'], Protocol::DFRN, $atom, false, $target_item['guid']); + Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]); + Worker::defer(); } if (($deliver_status >= 200) && ($deliver_status <= 299)) {