mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 06:42:42 +01:00
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
This commit is contained in:
parent
f34246a723
commit
041040c422
4 changed files with 74 additions and 1 deletions
|
@ -1140,6 +1140,15 @@ return array(
|
|||
// to work properly.
|
||||
'feed.public' => false,
|
||||
|
||||
// If you set this to a list of http URIs, when a feed story is published a
|
||||
// task will be created for each uri that posts the story data to the uri.
|
||||
// Daemons automagically retry failures 100 times, waiting $fail_count * 60s
|
||||
// between each subsequent failure. Be sure to keep the daemon console
|
||||
// (/daemon/) open while developing and testing your end points.
|
||||
//
|
||||
// NOTE: URIs are not validated, the URI must return http status 200 within
|
||||
// 30 seconds, and no permission checks are performed.
|
||||
'feed.http-hooks' => array(),
|
||||
|
||||
// -- Drydock --------------------------------------------------------------- //
|
||||
|
||||
|
|
|
@ -440,6 +440,7 @@ phutil_register_library_map(array(
|
|||
'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php',
|
||||
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
|
||||
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
|
||||
'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php',
|
||||
'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php',
|
||||
'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php',
|
||||
'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php',
|
||||
|
@ -1672,6 +1673,7 @@ phutil_register_library_map(array(
|
|||
'DrydockResourceStatus' => 'DrydockConstants',
|
||||
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
|
||||
'DrydockWebrootInterface' => 'DrydockInterface',
|
||||
'FeedPublisherWorker' => 'PhabricatorWorker',
|
||||
'HarbormasterDAO' => 'PhabricatorLiskDAO',
|
||||
'HarbormasterObject' => 'HarbormasterDAO',
|
||||
'HarbormasterScratchTable' => 'HarbormasterDAO',
|
||||
|
|
|
@ -119,10 +119,18 @@ final class PhabricatorFeedStoryPublisher {
|
|||
$this->insertNotifications($chrono_key);
|
||||
$this->sendNotification($chrono_key);
|
||||
}
|
||||
|
||||
$uris = PhabricatorEnv::getEnvConfig('feed.http-hooks', array());
|
||||
foreach ($uris as $uri) {
|
||||
$task = PhabricatorWorker::scheduleTask(
|
||||
'FeedPublisherWorker',
|
||||
array('chrono_key' => $chrono_key, 'uri' => $uri)
|
||||
);
|
||||
}
|
||||
|
||||
return $story;
|
||||
}
|
||||
|
||||
|
||||
private function insertNotifications($chrono_key) {
|
||||
$subscribed_phids = $this->subscribedPHIDs;
|
||||
$subscribed_phids = array_diff(
|
||||
|
|
54
src/applications/feed/worker/FeedPublisherWorker.php
Normal file
54
src/applications/feed/worker/FeedPublisherWorker.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class FeedPublisherWorker extends PhabricatorWorker {
|
||||
|
||||
protected function doWork() {
|
||||
$task_data = $this->getTaskData();
|
||||
$chrono_key = $task_data['chrono_key'];
|
||||
$uri = $task_data['uri'];
|
||||
|
||||
$story = id(new PhabricatorFeedStoryData())
|
||||
->loadOneWhere('chronologicalKey = %s', $chrono_key);
|
||||
|
||||
if (!$story) {
|
||||
throw new PhabricatorWorkerPermanentFailureException(
|
||||
'Feed story was deleted.'
|
||||
);
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'storyID' => $story->getID(),
|
||||
'storyType' => $story->getStoryType(),
|
||||
'storyData' => $story->getStoryData(),
|
||||
'storyAuthorPHID' => $story->getAuthorPHID(),
|
||||
'epoch' => $story->getEpoch(),
|
||||
);
|
||||
|
||||
id(new HTTPFuture($uri, $data))
|
||||
->setMethod('POST')
|
||||
->setTimeout(30)
|
||||
->resolvex();
|
||||
|
||||
}
|
||||
|
||||
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
|
||||
return max($task->getFailureCount(), 1) * 60;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue