@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

post feed stories to arbitrary uris via a new Worker

Summary: so folks can write applications and whatnot.

Test Plan: set feed.http-hooks to local dev instance (200) and localhost (500) in my conf. Verified succcess and retrying respectively.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T305

Differential Revision: https://secure.phabricator.com/D3874

+74 -1
+9
conf/default.conf.php
··· 1140 1140 // to work properly. 1141 1141 'feed.public' => false, 1142 1142 1143 + // If you set this to a list of http URIs, when a feed story is published a 1144 + // task will be created for each uri that posts the story data to the uri. 1145 + // Daemons automagically retry failures 100 times, waiting $fail_count * 60s 1146 + // between each subsequent failure. Be sure to keep the daemon console 1147 + // (/daemon/) open while developing and testing your end points. 1148 + // 1149 + // NOTE: URIs are not validated, the URI must return http status 200 within 1150 + // 30 seconds, and no permission checks are performed. 1151 + 'feed.http-hooks' => array(), 1143 1152 1144 1153 // -- Drydock --------------------------------------------------------------- // 1145 1154
+2
src/__phutil_library_map__.php
··· 440 440 'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php', 441 441 'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php', 442 442 'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php', 443 + 'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php', 443 444 'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php', 444 445 'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php', 445 446 'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php', ··· 1672 1673 'DrydockResourceStatus' => 'DrydockConstants', 1673 1674 'DrydockSSHCommandInterface' => 'DrydockCommandInterface', 1674 1675 'DrydockWebrootInterface' => 'DrydockInterface', 1676 + 'FeedPublisherWorker' => 'PhabricatorWorker', 1675 1677 'HarbormasterDAO' => 'PhabricatorLiskDAO', 1676 1678 'HarbormasterObject' => 'HarbormasterDAO', 1677 1679 'HarbormasterScratchTable' => 'HarbormasterDAO',
+9 -1
src/applications/feed/PhabricatorFeedStoryPublisher.php
··· 119 119 $this->insertNotifications($chrono_key); 120 120 $this->sendNotification($chrono_key); 121 121 } 122 + 123 + $uris = PhabricatorEnv::getEnvConfig('feed.http-hooks', array()); 124 + foreach ($uris as $uri) { 125 + $task = PhabricatorWorker::scheduleTask( 126 + 'FeedPublisherWorker', 127 + array('chrono_key' => $chrono_key, 'uri' => $uri) 128 + ); 129 + } 130 + 122 131 return $story; 123 132 } 124 - 125 133 126 134 private function insertNotifications($chrono_key) { 127 135 $subscribed_phids = $this->subscribedPHIDs;
+54
src/applications/feed/worker/FeedPublisherWorker.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class FeedPublisherWorker extends PhabricatorWorker { 20 + 21 + protected function doWork() { 22 + $task_data = $this->getTaskData(); 23 + $chrono_key = $task_data['chrono_key']; 24 + $uri = $task_data['uri']; 25 + 26 + $story = id(new PhabricatorFeedStoryData()) 27 + ->loadOneWhere('chronologicalKey = %s', $chrono_key); 28 + 29 + if (!$story) { 30 + throw new PhabricatorWorkerPermanentFailureException( 31 + 'Feed story was deleted.' 32 + ); 33 + } 34 + 35 + $data = array( 36 + 'storyID' => $story->getID(), 37 + 'storyType' => $story->getStoryType(), 38 + 'storyData' => $story->getStoryData(), 39 + 'storyAuthorPHID' => $story->getAuthorPHID(), 40 + 'epoch' => $story->getEpoch(), 41 + ); 42 + 43 + id(new HTTPFuture($uri, $data)) 44 + ->setMethod('POST') 45 + ->setTimeout(30) 46 + ->resolvex(); 47 + 48 + } 49 + 50 + public function getWaitBeforeRetry(PhabricatorWorkerTask $task) { 51 + return max($task->getFailureCount(), 1) * 60; 52 + } 53 + 54 + }