Merge pull request #5998 from annando/ap-queue
Unsuccessful ActivitiyPub transmission are now deferred
This commit is contained in:
commit
dbe49a0c1a
4 changed files with 34 additions and 14 deletions
|
@ -243,7 +243,9 @@ class Worker
|
|||
self::execFunction($queue, $include, $argv, true);
|
||||
|
||||
$stamp = (float)microtime(true);
|
||||
if (DBA::update('workerqueue', ['done' => true], ['id' => $queue['id']])) {
|
||||
|
||||
$condition = ["`id` = ? AND `next_try` < ?", $queue['id'], DateTimeFormat::utcNow()];
|
||||
if (DBA::update('workerqueue', ['done' => true], $condition)) {
|
||||
Config::set('system', 'last_worker_execution', DateTimeFormat::utcNow());
|
||||
}
|
||||
self::$db_duration = (microtime(true) - $stamp);
|
||||
|
@ -1137,8 +1139,8 @@ class Worker
|
|||
$id = $queue['id'];
|
||||
|
||||
if ($retrial > 14) {
|
||||
logger('Id ' . $id . ' had been tried 14 times, it will be deleted now.', LOGGER_DEBUG);
|
||||
DBA::delete('workerqueue', ['id' => $id]);
|
||||
logger('Id ' . $id . ' had been tried 14 times. We stop now.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate the delay until the next trial
|
||||
|
|
|
@ -936,6 +936,8 @@ class Transmitter
|
|||
* @param integer $uid User ID
|
||||
* @param string $inbox Target inbox
|
||||
* @param integer $suggestion_id Suggestion ID
|
||||
*
|
||||
* @return boolean was the transmission successful?
|
||||
*/
|
||||
public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
|
||||
{
|
||||
|
@ -957,7 +959,7 @@ class Transmitter
|
|||
$signed = LDSignature::sign($data, $owner);
|
||||
|
||||
logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
|
||||
HTTPSignature::transmit($signed, $inbox, $uid);
|
||||
return HTTPSignature::transmit($signed, $inbox, $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -965,6 +967,8 @@ class Transmitter
|
|||
*
|
||||
* @param integer $uid User ID
|
||||
* @param string $inbox Target inbox
|
||||
*
|
||||
* @return boolean was the transmission successful?
|
||||
*/
|
||||
public static function sendProfileDeletion($uid, $inbox)
|
||||
{
|
||||
|
@ -984,7 +988,7 @@ class Transmitter
|
|||
$signed = LDSignature::sign($data, $owner);
|
||||
|
||||
logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
|
||||
HTTPSignature::transmit($signed, $inbox, $uid);
|
||||
return HTTPSignature::transmit($signed, $inbox, $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -992,6 +996,8 @@ class Transmitter
|
|||
*
|
||||
* @param integer $uid User ID
|
||||
* @param string $inbox Target inbox
|
||||
*
|
||||
* @return boolean was the transmission successful?
|
||||
*/
|
||||
public static function sendProfileUpdate($uid, $inbox)
|
||||
{
|
||||
|
@ -1011,7 +1017,7 @@ class Transmitter
|
|||
$signed = LDSignature::sign($data, $owner);
|
||||
|
||||
logger('Deliver profile update for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
|
||||
HTTPSignature::transmit($signed, $inbox, $uid);
|
||||
return HTTPSignature::transmit($signed, $inbox, $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -272,9 +272,11 @@ class HTTPSignature
|
|||
/**
|
||||
* @brief Transmit given data to a target for a user
|
||||
*
|
||||
* @param $data
|
||||
* @param $target
|
||||
* @param $uid
|
||||
* @param array $data Data that is about to be send
|
||||
* @param string $target The URL of the inbox
|
||||
* @param integer $uid User id of the sender
|
||||
*
|
||||
* @return boolean Was the transmission successful?
|
||||
*/
|
||||
public static function transmit($data, $target, $uid)
|
||||
{
|
||||
|
@ -303,8 +305,11 @@ class HTTPSignature
|
|||
$headers[] = 'Content-Type: application/activity+json';
|
||||
|
||||
$postResult = Network::post($target, $content, $headers);
|
||||
$return_code = $postResult->getReturnCode();
|
||||
|
||||
logger('Transmit to ' . $target . ' returned ' . $postResult->getReturnCode());
|
||||
logger('Transmit to ' . $target . ' returned ' . $return_code);
|
||||
|
||||
return ($return_code >= 200) && ($return_code <= 299);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Friendica\Worker;
|
|||
use Friendica\BaseObject;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Util\HTTPSignature;
|
||||
|
||||
class APDelivery extends BaseObject
|
||||
|
@ -23,19 +24,25 @@ class APDelivery extends BaseObject
|
|||
{
|
||||
logger('Invoked: ' . $cmd . ': ' . $item_id . ' to ' . $inbox, LOGGER_DEBUG);
|
||||
|
||||
$success = true;
|
||||
|
||||
if ($cmd == Delivery::MAIL) {
|
||||
} elseif ($cmd == Delivery::SUGGESTION) {
|
||||
ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
|
||||
$success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
|
||||
} elseif ($cmd == Delivery::RELOCATION) {
|
||||
} elseif ($cmd == Delivery::REMOVAL) {
|
||||
ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
|
||||
$success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);
|
||||
} elseif ($cmd == Delivery::PROFILEUPDATE) {
|
||||
ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
|
||||
$success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
|
||||
} else {
|
||||
$data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
|
||||
if (!empty($data)) {
|
||||
HTTPSignature::transmit($data, $inbox, $uid);
|
||||
$success = HTTPSignature::transmit($data, $inbox, $uid);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
Worker::defer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue