3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
23 * Send a raw WebSub push atom update from our internal hub.
25 * @author Brion Vibber <brion@status.net>
27 class HubOutQueueHandler extends QueueHandler
34 function handle($data)
36 assert(array_key_exists('atom', $data));
37 assert(is_string($data['atom']));
38 $atom = $data['atom'];
40 assert(array_key_exists('retries', $data));
41 $retries = intval($data['retries']);
43 if (array_key_exists('topic', $data) && array_key_exists('callback', $data)) {
44 assert(is_string($data['topic']));
45 assert(is_string($data['callback']));
47 $sub = HubSub::getByHashkey($data['topic'], $data['callback']);
48 } elseif (array_key_exists('sub', $data)) {
49 // queue behaviour changed 2017-07-09 to store topic/callback instead of sub object
50 common_debug('Legacy behaviour of storing HubSub objects found, this should go away when all objects are handled...');
53 throw new ServerException('No HubSub object available with queue item data.');
55 assert($sub instanceof HubSub);
58 $success = $sub->push($atom);
59 // The reason I split these up is because I want to see how the algorithm acts in practice.
61 common_debug('HubSub push completed successfully!');
63 common_debug('HubSub push failed with an HTTP error.');
65 if ($sub->getErrors()>0) {
66 common_debug('Resetting HubSub push error count following successful reset.');
69 } catch (AlreadyFulfilledException $e) {
70 // Probably doesn't happen anymore since commit 74a60ab963b5ce1ed95bd81f935a44c573cd0264
71 common_log(LOG_INFO, "Failed WebSub push to $sub->callback for $sub->topic (".get_class($e)."): " . $e->getMessage());
72 } catch (Exception $e) {
74 $msg = "Failed WebSub push to $sub->callback for $sub->topic (".get_class($e)."): " . $e->getMessage();
76 common_log(LOG_INFO, "$msg; scheduling for $retries more tries");
78 // @fixme when we have infrastructure to schedule a retry
79 // after a delay, use it.
80 $sub->distribute($atom, $retries);
82 $sub->incrementErrors($e->getMessage());
83 common_log(LOG_ERR, "$msg; discarding");