use Friendica\Database\DBA;
use BadMethodCallException;
use Friendica\Database\Database;
+use Friendica\DI;
use Friendica\Model\ItemURI;
class Delivery
DBA::delete('post-delivery', ['uri-id' => $uri_id, 'inbox-id' => ItemURI::getIdByURI($inbox)]);
}
+ /**
+ * Remove failed posts for an inbox
+ *
+ * @param string $inbox
+ */
+ public static function removeFailed(string $inbox)
+ {
+ DBA::delete('post-delivery', ["`inbox-id` = ? AND `failed` >= ?", ItemURI::getIdByURI($inbox), DI::config()->get('system', 'worker_defer_limit')]);
+ }
+
/**
* Increment "failed" counter for the given inbox and post
*
public static function selectForInbox(string $inbox)
{
- return DBA::selectToArray('post-delivery', [], ["`inbox-id` = ? AND `failed` < ?", ItemURI::getIdByURI($inbox), 15], ['order' => ['created']]);
+ return DBA::selectToArray('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['order' => ['created']]);
}
}
private static function deliver(string $inbox)
{
+ Post\Delivery::removeFailed($inbox);
+
$uri_ids = [];
$posts = Post\Delivery::selectForInbox($inbox);
- $success = empty($posts);
foreach ($posts as $post) {
- if (self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], [], $post['uri-id'])) {
- $success = true;
- } else {
+ if (!self::deliverToInbox($post['command'], 0, $inbox, $post['uid'], [], $post['uri-id'])) {
$uri_ids[] = $post['uri-id'];
}
}
- return ['success' => $success, 'uri_ids' => $uri_ids];
+ return ['success' => empty($uri_ids), 'uri_ids' => $uri_ids];
}
private static function deliverToInbox(string $cmd, int $item_id, string $inbox, int $uid, array $receivers, int $uri_id)