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);
$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
* @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)
{
$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);
}
/**
*
* @param integer $uid User ID
* @param string $inbox Target inbox
+ *
+ * @return boolean was the transmission successful?
*/
public static function sendProfileDeletion($uid, $inbox)
{
$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);
}
/**
*
* @param integer $uid User ID
* @param string $inbox Target inbox
+ *
+ * @return boolean was the transmission successful?
*/
public static function sendProfileUpdate($uid, $inbox)
{
$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);
}
/**
/**
* @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)
{
$headers[] = 'Content-Type: application/activity+json';
$postResult = Network::post($target, $content, $headers);
+ $return_code = $postResult->getReturnCode();
+
+ logger('Transmit to ' . $target . ' returned ' . $return_code);
- logger('Transmit to ' . $target . ' returned ' . $postResult->getReturnCode());
+ return ($return_code >= 200) && ($return_code <= 299);
}
/**
use Friendica\BaseObject;
use Friendica\Protocol\ActivityPub;
use Friendica\Model\Item;
+use Friendica\Core\Worker;
use Friendica\Util\HTTPSignature;
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();
+ }
}
}