2018-05-17 23:30:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file src/Model/PushSubscriber.php
|
|
|
|
*/
|
|
|
|
namespace Friendica\Model;
|
|
|
|
|
|
|
|
use Friendica\Core\Worker;
|
|
|
|
use dba;
|
|
|
|
|
|
|
|
require_once 'include/dba.php';
|
|
|
|
|
|
|
|
class PushSubscriber
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $priority Priority for push workers
|
|
|
|
*/
|
2018-05-17 23:47:15 +00:00
|
|
|
public static function publishFeed($default_priority = PRIORITY_HIGH)
|
2018-05-17 23:30:49 +00:00
|
|
|
{
|
|
|
|
// We'll push to each subscriber that has push > 0,
|
|
|
|
// i.e. there has been an update (set in notifier.php).
|
2018-05-17 23:43:44 +00:00
|
|
|
$subscribers = dba::select('push_subscriber', ['id', 'push', 'callback_url'], ["`push` > 0 AND `next_try` < UTC_TIMESTAMP()"]);
|
2018-05-17 23:30:49 +00:00
|
|
|
|
|
|
|
while ($subscriber = dba::fetch($subscribers)) {
|
2018-05-17 23:43:44 +00:00
|
|
|
// We always handle retries with low priority
|
|
|
|
if ($subscriber["push"] > 1) {
|
|
|
|
$priority = PRIORITY_LOW;
|
2018-05-17 23:47:15 +00:00
|
|
|
} else {
|
|
|
|
$priority = $default_priority;
|
2018-05-17 23:43:44 +00:00
|
|
|
}
|
2018-05-17 23:47:15 +00:00
|
|
|
|
2018-05-17 23:43:44 +00:00
|
|
|
logger("Publish feed to " . $subscriber["callback_url"] . " with priority " . $priority, LOGGER_DEBUG);
|
2018-05-17 23:30:49 +00:00
|
|
|
Worker::add($priority, 'PubSubPublish', (int)$subscriber["id"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
dba::close($subscribers);
|
|
|
|
}
|
|
|
|
}
|