X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FPubSubPublish.php;h=1e18b4ccfa097b81aedcfb364e60754bc18a545d;hb=cbfc3d0c28e0b55c3ccf1ddfd321798a8c2532e8;hp=27b6f3d9a16853ef3a398ecd275f4edd08bfb56b;hpb=61824119e41c514951106dd525714e264d1435de;p=friendica.git diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index 27b6f3d9a1..1e18b4ccfa 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -5,19 +5,17 @@ namespace Friendica\Worker; -use Friendica\App; +use Friendica\BaseObject; use Friendica\Core\System; -use Friendica\Core\Config; -use Friendica\Core\Worker; -use Friendica\Database\DBM; +use Friendica\Database\DBA; +use Friendica\Model\PushSubscriber; use Friendica\Protocol\OStatus; use Friendica\Util\Network; -use Friendica\Util\DateTimeFormat; -use dba; require_once 'include/items.php'; -class PubSubPublish { +class PubSubPublish +{ public static function execute($pubsubpublish_id = 0) { if ($pubsubpublish_id == 0) { @@ -27,11 +25,12 @@ class PubSubPublish { self::publish($pubsubpublish_id); } - private static function publish($id) { - global $a; + private static function publish($id) + { + $a = BaseObject::getApp(); - $subscriber = dba::selectFirst('push_subscriber', [], ['id' => $id]); - if (!DBM::is_result($subscriber)) { + $subscriber = DBA::selectFirst('push_subscriber', [], ['id' => $id]); + if (!DBA::isResult($subscriber)) { return; } @@ -65,30 +64,11 @@ class PubSubPublish { if ($ret >= 200 && $ret <= 299) { logger('Successfully pushed to ' . $subscriber['callback_url']); - // set last_update to the "created" date of the last item, and reset push=0 - $fields = ['push' => 0, 'next_try' => NULL_DATE, 'last_update' => $last_update]; - dba::update('push_subscriber', $fields, $condition); - + PushSubscriber::reset($subscriber['id'], $last_update); } else { logger('Delivery error when pushing to ' . $subscriber['callback_url'] . ' HTTP: ' . $ret); - // we use the push variable also as a counter, if we failed we - // increment this until some upper limit where we give up - $retrial = $subscriber['push']; - - if ($retrial > 14) { - dba::update('push_subscriber', ['push' => 0, 'next_try' => NULL_DATE], $condition); - logger('Delivery error: Giving up for ' . $subscriber['callback_url'], LOGGER_DEBUG); - } else { - // Calculate the delay until the next trial - $delay = (($retrial + 3) ** 4) + (rand(1, 30) * ($retrial + 1)); - $next = DateTimeFormat::utc('now + ' . $delay . ' seconds'); - - $retrial = $retrial + 1; - - dba::update('push_subscriber', ['push' => $retrial, 'next_try' => $next], $condition); - logger('Delivery error: Next try (' . $retrial . ') for ' . $subscriber['callback_url'] . ' at ' . $next, LOGGER_DEBUG); - } + PushSubscriber::delay($subscriber['id']); } } }