kopia lustrzana https://github.com/nextcloud/social
cleaning and renaming upsteam request caching
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/374/head
rodzic
d685af4008
commit
fd2ef9e6ce
|
@ -38,10 +38,10 @@ return [
|
|||
'routes' => [
|
||||
['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'],
|
||||
['name' => 'Navigation#test', 'url' => '/test', 'verb' => 'GET'],
|
||||
|
||||
[
|
||||
'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET',
|
||||
'requirements' => ['path' => '.+'], 'defaults' => ['path' => '']
|
||||
'requirements' => ['path' => '.+'],
|
||||
'defaults' => ['path' => '']
|
||||
],
|
||||
['name' => 'Navigation#documentGet', 'url' => '/document/get', 'verb' => 'GET'],
|
||||
['name' => 'Navigation#documentGetPublic', 'url' => '/document/public', 'verb' => 'GET'],
|
||||
|
@ -84,12 +84,8 @@ return [
|
|||
|
||||
['name' => 'Local#documentsCache', 'url' => '/api/v1/documents/cache', 'verb' => 'POST'],
|
||||
|
||||
['name' => 'Queue#asyncWithToken', 'url' => CurlService::ASYNC_TOKEN, 'verb' => 'POST'],
|
||||
|
||||
[
|
||||
'name' => 'Config#setCloudAddress', 'url' => '/api/v1/config/cloudAddress',
|
||||
'verb' => 'POST'
|
||||
],
|
||||
['name' => 'Queue#asyncForRequest', 'url' => CurlService::ASYNC_REQUEST_TOKEN, 'verb' => 'POST'],
|
||||
|
||||
['name' => 'Config#setCloudAddress', 'url' => '/api/v1/config/cloudAddress', 'verb' => 'POST']
|
||||
]
|
||||
];
|
||||
|
|
|
@ -36,7 +36,8 @@ use OCA\Social\Exceptions\SocialAppConfigException;
|
|||
use OCA\Social\Service\ActivityService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\QueueService;
|
||||
use OCA\Social\Service\RequestQueueService;
|
||||
use OCA\Social\Service\StreamQueueService;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
|
@ -47,8 +48,11 @@ class QueueProcess extends Base {
|
|||
/** @var ActivityService */
|
||||
private $activityService;
|
||||
|
||||
/** @var QueueService */
|
||||
private $queueService;
|
||||
/** @var StreamQueueService */
|
||||
private $streamQueueService;
|
||||
|
||||
/** @var RequestQueueService */
|
||||
private $requestQueueService;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
@ -61,18 +65,21 @@ class QueueProcess extends Base {
|
|||
* NoteCreate constructor.
|
||||
*
|
||||
* @param ActivityService $activityService
|
||||
* @param QueueService $queueService
|
||||
* @param RequestQueueService $requestQueueService
|
||||
* @param StreamQueueService $streamQueueService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ActivityService $activityService, QueueService $queueService, ConfigService $configService,
|
||||
ActivityService $activityService, RequestQueueService $requestQueueService,
|
||||
StreamQueueService $streamQueueService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->activityService = $activityService;
|
||||
$this->queueService = $queueService;
|
||||
$this->requestQueueService = $requestQueueService;
|
||||
$this->streamQueueService = $streamQueueService;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
@ -94,14 +101,24 @@ class QueueProcess extends Base {
|
|||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||
|
||||
$requests = $this->queueService->getRequestStandby($total = 0);
|
||||
$output->writeLn('processing requests queue');
|
||||
$this->processRequestQueue($output);
|
||||
|
||||
$output->writeLn('found a total of ' . $total . ' requests in the queue');
|
||||
$output->writeLn('processing stream queue');
|
||||
$this->processStreamQueue($output);
|
||||
}
|
||||
|
||||
|
||||
private function processRequestQueue(OutputInterface $output) {
|
||||
$total = 0;
|
||||
$requests = $this->requestQueueService->getRequestStandby($total);
|
||||
|
||||
$output->writeLn('- found a total of ' . $total . ' requests in the queue');
|
||||
if ($total === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeLn(sizeof($requests) . ' are processable at this time');
|
||||
$output->writeLn('- ' . sizeof($requests) . ' are processable at this time');
|
||||
if (sizeof($requests) === 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -119,5 +136,27 @@ class QueueProcess extends Base {
|
|||
$output->writeLn('done');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function processStreamQueue(OutputInterface $output) {
|
||||
$total = 0;
|
||||
$items = $this->streamQueueService->getRequestStandby($total);
|
||||
|
||||
$output->writeLn('- found a total of ' . $total . ' not cached object in the queue');
|
||||
if ($total === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeLn('- ' . sizeof($items) . ' are processable at this time');
|
||||
if (sizeof($items) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$output->write('.');
|
||||
$this->streamQueueService->manageStreamQueue($item);
|
||||
}
|
||||
|
||||
$output->writeLn('done');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ use Exception;
|
|||
use OC\Core\Command\Base;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\QueueService;
|
||||
use OCA\Social\Service\RequestQueueService;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -46,8 +46,8 @@ class QueueStatus extends Base {
|
|||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var QueueService */
|
||||
private $queueService;
|
||||
/** @var RequestQueueService */
|
||||
private $requestQueueService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
@ -56,16 +56,16 @@ class QueueStatus extends Base {
|
|||
/**
|
||||
* NoteCreate constructor.
|
||||
*
|
||||
* @param QueueService $queueService
|
||||
* @param RequestQueueService $requestQueueService
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
QueueService $queueService, ConfigService $configService, MiscService $miscService
|
||||
RequestQueueService $requestQueueService, ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->queueService = $queueService;
|
||||
$this->requestQueueService = $requestQueueService;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class QueueStatus extends Base {
|
|||
throw new Exception('As of today, --token is mandatory');
|
||||
}
|
||||
|
||||
$requests = $this->queueService->getRequestFromToken($token);
|
||||
$requests = $this->requestQueueService->getRequestFromToken($token);
|
||||
|
||||
foreach ($requests as $request) {
|
||||
$output->writeLn(json_encode($request));
|
||||
|
|
|
@ -36,7 +36,7 @@ use OCA\Social\Exceptions\SocialAppConfigException;
|
|||
use OCA\Social\Model\RequestQueue;
|
||||
use OCA\Social\Service\ActivityService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\QueueService;
|
||||
use OCA\Social\Service\RequestQueueService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IRequest;
|
||||
|
||||
|
@ -51,8 +51,8 @@ class QueueController extends Controller {
|
|||
|
||||
use TAsync;
|
||||
|
||||
/** @var QueueService */
|
||||
private $queueService;
|
||||
/** @var RequestQueueService */
|
||||
private $requestQueueService;
|
||||
|
||||
/** @var ActivityService */
|
||||
private $activityService;
|
||||
|
@ -65,17 +65,17 @@ class QueueController extends Controller {
|
|||
* QueueController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param QueueService $queueService
|
||||
* @param RequestQueueService $requestQueueService
|
||||
* @param ActivityService $activityService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, QueueService $queueService, ActivityService $activityService,
|
||||
IRequest $request, RequestQueueService $requestQueueService, ActivityService $activityService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->queueService = $queueService;
|
||||
$this->requestQueueService = $requestQueueService;
|
||||
$this->activityService = $activityService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
@ -87,8 +87,8 @@ class QueueController extends Controller {
|
|||
*
|
||||
* @param string $token
|
||||
*/
|
||||
public function asyncWithToken(string $token) {
|
||||
$requests = $this->queueService->getRequestFromToken($token, RequestQueue::STATUS_STANDBY);
|
||||
public function asyncForRequest(string $token) {
|
||||
$requests = $this->requestQueueService->getRequestFromToken($token, RequestQueue::STATUS_STANDBY);
|
||||
|
||||
if (!empty($requests)) {
|
||||
$this->async();
|
||||
|
|
|
@ -36,7 +36,7 @@ use OCA\Social\AppInfo\Application;
|
|||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Service\ActivityService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\QueueService;
|
||||
use OCA\Social\Service\RequestQueueService;
|
||||
use OCP\AppFramework\QueryException;
|
||||
|
||||
|
||||
|
@ -51,7 +51,7 @@ class Queue extends TimedJob {
|
|||
/** @var ActivityService */
|
||||
private $activityService;
|
||||
|
||||
/** @var QueueService */
|
||||
/** @var RequestQueueService */
|
||||
private $queueService;
|
||||
|
||||
/** @var MiscService */
|
||||
|
@ -75,7 +75,7 @@ class Queue extends TimedJob {
|
|||
$app = new Application();
|
||||
$c = $app->getContainer();
|
||||
|
||||
$this->queueService = $c->query(QueueService::class);
|
||||
$this->queueService = $c->query(RequestQueueService::class);
|
||||
$this->activityService = $c->query(ActivityService::class);
|
||||
$this->miscService = $c->query(MiscService::class);
|
||||
|
||||
|
|
|
@ -63,6 +63,8 @@ class CoreRequestBuilder {
|
|||
const TABLE_CACHE_ACTORS = 'social_cache_actors';
|
||||
const TABLE_CACHE_DOCUMENTS = 'social_cache_documents';
|
||||
|
||||
const TABLE_QUEUE_STREAM = 'social_queue_stream';
|
||||
|
||||
|
||||
/** @var IDBConnection */
|
||||
protected $dbConnection;
|
||||
|
|
|
@ -82,9 +82,8 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->select(
|
||||
'sn.id', 'sn.type', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content',
|
||||
'sn.summary',
|
||||
'sn.published', 'sn.published_time', 'sn.attributed_to', 'sn.in_reply_to', 'sn.source',
|
||||
'sn.local', 'sn.instances', 'sn.creation'
|
||||
'sn.summary', 'sn.published', 'sn.published_time', 'sn.cache', 'sn.attributed_to',
|
||||
'sn.in_reply_to', 'sn.source', 'sn.local', 'sn.instances', 'sn.creation'
|
||||
)
|
||||
->from(self::TABLE_SERVER_NOTES, 'sn');
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
* @param RequestQueue $queue
|
||||
*/
|
||||
public function create(RequestQueue $queue) {
|
||||
$qb = $this->getQueueInsertSql();
|
||||
$qb = $this->getRequestQueueInsertSql();
|
||||
$qb->setValue('token', $qb->createNamedParameter($queue->getToken()))
|
||||
->setValue('author', $qb->createNamedParameter($queue->getAuthor()))
|
||||
->setValue('activity', $qb->createNamedParameter($queue->getActivity()))
|
||||
|
@ -85,14 +85,14 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
* @return RequestQueue[]
|
||||
*/
|
||||
public function getStandby(): array {
|
||||
$qb = $this->getQueueSelectSql();
|
||||
$qb = $this->getRequestQueueSelectSql();
|
||||
$this->limitToStatus($qb, RequestQueue::STATUS_STANDBY);
|
||||
$qb->orderBy('id', 'asc');
|
||||
|
||||
$requests = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$requests[] = $this->parseQueueSelectSql($data);
|
||||
$requests[] = $this->parseRequestQueueSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
|
@ -109,7 +109,7 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
* @return RequestQueue[]
|
||||
*/
|
||||
public function getFromToken(string $token, int $status = -1): array {
|
||||
$qb = $this->getQueueSelectSql();
|
||||
$qb = $this->getRequestQueueSelectSql();
|
||||
$this->limitToToken($qb, $token);
|
||||
|
||||
if ($status > -1) {
|
||||
|
@ -121,7 +121,7 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
$requests = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$requests[] = $this->parseQueueSelectSql($data);
|
||||
$requests[] = $this->parseRequestQueueSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
|
@ -135,7 +135,7 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
* @throws QueueStatusException
|
||||
*/
|
||||
public function setAsRunning(RequestQueue &$queue) {
|
||||
$qb = $this->getQueueUpdateSql();
|
||||
$qb = $this->getRequestQueueUpdateSql();
|
||||
$qb->set('status', $qb->createNamedParameter(RequestQueue::STATUS_RUNNING))
|
||||
->set(
|
||||
'last',
|
||||
|
@ -160,7 +160,7 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
* @throws QueueStatusException
|
||||
*/
|
||||
public function setAsSuccess(RequestQueue &$queue) {
|
||||
$qb = $this->getQueueUpdateSql();
|
||||
$qb = $this->getRequestQueueUpdateSql();
|
||||
$qb->set('status', $qb->createNamedParameter(RequestQueue::STATUS_SUCCESS));
|
||||
$this->limitToId($qb, $queue->getId());
|
||||
$this->limitToStatus($qb, RequestQueue::STATUS_RUNNING);
|
||||
|
@ -176,12 +176,12 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
|
||||
|
||||
/**
|
||||
* @param RequestQueue $queue >ll
|
||||
* @param RequestQueue $queue
|
||||
*
|
||||
* @throws QueueStatusException
|
||||
*/
|
||||
public function setAsFailure(RequestQueue &$queue) {
|
||||
$qb = $this->getQueueUpdateSql();
|
||||
$qb = $this->getRequestQueueUpdateSql();
|
||||
$func = $qb->func();
|
||||
$expr = $qb->expr();
|
||||
|
||||
|
@ -201,7 +201,7 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
|
|||
|
||||
|
||||
public function delete(RequestQueue $queue) {
|
||||
$qb = $this->getQueueDeleteSql();
|
||||
$qb = $this->getRequestQueueDeleteSql();
|
||||
$this->limitToId($qb, $queue->getId());
|
||||
|
||||
$qb->execute();
|
||||
|
|
|
@ -45,7 +45,7 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getQueueInsertSql(): IQueryBuilder {
|
||||
protected function getRequestQueueInsertSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_REQUEST_QUEUE);
|
||||
|
||||
|
@ -58,7 +58,7 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getQueueUpdateSql(): IQueryBuilder {
|
||||
protected function getRequestQueueUpdateSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_REQUEST_QUEUE);
|
||||
|
||||
|
@ -71,7 +71,7 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getQueueSelectSql(): IQueryBuilder {
|
||||
protected function getRequestQueueSelectSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
|
@ -92,7 +92,7 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getQueueDeleteSql(): IQueryBuilder {
|
||||
protected function getRequestQueueDeleteSql(): IQueryBuilder {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_REQUEST_QUEUE);
|
||||
|
||||
|
@ -105,7 +105,7 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
|
|||
*
|
||||
* @return RequestQueue
|
||||
*/
|
||||
protected function parseQueueSelectSql($data): RequestQueue {
|
||||
protected function parseRequestQueueSelectSql($data): RequestQueue {
|
||||
$queue = new RequestQueue();
|
||||
$queue->importFromDatabase($data);
|
||||
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\Social\Migration;
|
||||
|
||||
|
||||
use Closure;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use Doctrine\DBAL\Schema\SchemaException;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use OCA\Social\Db\CoreRequestBuilder;
|
||||
use OCP\DB\ISchemaWrapper;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
|
||||
|
||||
/**
|
||||
* Class Version0001Date20190121153145
|
||||
*
|
||||
* @package OCA\Social\Migration
|
||||
*/
|
||||
class Version0002Date20190121153145 extends SimpleMigrationStep {
|
||||
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $connection;
|
||||
|
||||
|
||||
/**
|
||||
* @param IDBConnection $connection
|
||||
*/
|
||||
public function __construct(IDBConnection $connection) {
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||
* @param array $options
|
||||
*
|
||||
* @return ISchemaWrapper
|
||||
* @throws SchemaException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options
|
||||
): ISchemaWrapper {
|
||||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
$table = $schema->getTable(CoreRequestBuilder::TABLE_SERVER_NOTES);
|
||||
if (!$table->hasColumn('cache')) {
|
||||
$table->addColumn('cache', Type::TEXT, ['notnull' => false]);
|
||||
}
|
||||
|
||||
$table = $schema->getTable(CoreRequestBuilder::TABLE_SERVER_NOTES);
|
||||
if (!$table->hasColumn('activity_id')) {
|
||||
$table->addColumn('activity_id', Type::STRING, ['notnull' => false, 'length' => 255]);
|
||||
}
|
||||
|
||||
if (!$schema->hasTable(CoreRequestBuilder::TABLE_QUEUE_STREAM)) {
|
||||
$table = $schema->createTable(CoreRequestBuilder::TABLE_QUEUE_STREAM);
|
||||
$table->addColumn(
|
||||
'id', 'bigint', [
|
||||
'autoincrement' => true,
|
||||
'notnull' => true,
|
||||
'length' => 11,
|
||||
'unsigned' => true,
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'token', 'string', [
|
||||
'notnull' => true,
|
||||
'length' => 63,
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'stream_id', 'string', [
|
||||
'notnull' => true,
|
||||
'length' => 255,
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'type', 'string', [
|
||||
'notnull' => true,
|
||||
'length' => 31,
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'status', 'smallint', [
|
||||
'notnull' => false,
|
||||
'length' => 1,
|
||||
'default' => 0,
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'tries', 'smallint', [
|
||||
'notnull' => false,
|
||||
'length' => 2,
|
||||
'default' => 0,
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'last', 'datetime', [
|
||||
'notnull' => false,
|
||||
]
|
||||
);
|
||||
$table->setPrimaryKey(['id']);
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
||||
* @param array $options
|
||||
*/
|
||||
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ namespace OCA\Social\Model;
|
|||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use daita\MySmallPhpTools\Traits\TStringTools;
|
||||
use DateTime;
|
||||
use JsonSerializable;
|
||||
|
||||
|
@ -45,6 +46,7 @@ class RequestQueue implements JsonSerializable {
|
|||
|
||||
|
||||
use TArrayTools;
|
||||
use TStringTools;
|
||||
|
||||
|
||||
const STATUS_STANDBY = 0;
|
||||
|
@ -138,6 +140,16 @@ class RequestQueue implements JsonSerializable {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RequestQueue
|
||||
*/
|
||||
public function resetToken(): RequestQueue {
|
||||
$uuid = $this->uuid();
|
||||
$this->setToken($uuid);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -158,21 +170,6 @@ class RequestQueue implements JsonSerializable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return RequestQueue
|
||||
*/
|
||||
public function resetToken(): RequestQueue {
|
||||
$uuid = sprintf(
|
||||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
|
||||
$this->setToken($uuid);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -76,8 +76,8 @@ class ActivityService {
|
|||
/** @var SignatureService */
|
||||
private $signatureService;
|
||||
|
||||
/** @var QueueService */
|
||||
private $queueService;
|
||||
/** @var RequestQueueService */
|
||||
private $requestQueueService;
|
||||
|
||||
/** @var AccountService */
|
||||
private $accountService;
|
||||
|
@ -102,7 +102,7 @@ class ActivityService {
|
|||
* @param NotesRequest $notesRequest
|
||||
* @param FollowsRequest $followsRequest
|
||||
* @param SignatureService $signatureService
|
||||
* @param QueueService $queueService
|
||||
* @param RequestQueueService $requestQueueService
|
||||
* @param AccountService $accountService
|
||||
* @param CurlService $curlService
|
||||
* @param ConfigService $configService
|
||||
|
@ -110,13 +110,13 @@ class ActivityService {
|
|||
*/
|
||||
public function __construct(
|
||||
NotesRequest $notesRequest, FollowsRequest $followsRequest,
|
||||
SignatureService $signatureService, QueueService $queueService,
|
||||
SignatureService $signatureService, RequestQueueService $requestQueueService,
|
||||
AccountService $accountService, CurlService $curlService, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->notesRequest = $notesRequest;
|
||||
$this->followsRequest = $followsRequest;
|
||||
$this->queueService = $queueService;
|
||||
$this->requestQueueService = $requestQueueService;
|
||||
$this->accountService = $accountService;
|
||||
$this->signatureService = $signatureService;
|
||||
$this->curlService = $curlService;
|
||||
|
@ -217,11 +217,11 @@ class ActivityService {
|
|||
|
||||
$author = $this->getAuthorFromItem($activity);
|
||||
$instancePaths = $this->generateInstancePaths($activity);
|
||||
$token = $this->queueService->generateRequestQueue($instancePaths, $activity, $author);
|
||||
$token = $this->requestQueueService->generateRequestQueue($instancePaths, $activity, $author);
|
||||
$this->manageInit();
|
||||
|
||||
try {
|
||||
$directRequest = $this->queueService->getPriorityRequest($token);
|
||||
$directRequest = $this->requestQueueService->getPriorityRequest($token);
|
||||
$directRequest->setTimeout(self::TIMEOUT_LIVE);
|
||||
$this->manageRequest($directRequest);
|
||||
} catch (NoHighPriorityRequestException $e) {
|
||||
|
@ -229,7 +229,7 @@ class ActivityService {
|
|||
return '';
|
||||
}
|
||||
|
||||
$requests = $this->queueService->getRequestFromToken($token, RequestQueue::STATUS_STANDBY);
|
||||
$requests = $this->requestQueueService->getRequestFromToken($token, RequestQueue::STATUS_STANDBY);
|
||||
if (sizeof($requests) > 0) {
|
||||
$this->curlService->asyncWithToken($token);
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ class ActivityService {
|
|||
}
|
||||
|
||||
try {
|
||||
$this->queueService->initRequest($queue);
|
||||
$this->requestQueueService->initRequest($queue);
|
||||
} catch (QueueStatusException $e) {
|
||||
return;
|
||||
}
|
||||
|
@ -266,24 +266,24 @@ class ActivityService {
|
|||
try {
|
||||
$this->signatureService->signRequest($request, $queue);
|
||||
$this->curlService->request($request);
|
||||
$this->queueService->endRequest($queue, true);
|
||||
$this->requestQueueService->endRequest($queue, true);
|
||||
} catch (RequestResultNotJsonException $e) {
|
||||
$this->queueService->endRequest($queue, true);
|
||||
$this->requestQueueService->endRequest($queue, true);
|
||||
} catch (ActorDoesNotExistException $e) {
|
||||
$this->miscService->log(
|
||||
'Error while managing request: ' . json_encode($request) . ' ' . $e->getMessage(), 1
|
||||
);
|
||||
$this->queueService->deleteRequest($queue);
|
||||
$this->requestQueueService->deleteRequest($queue);
|
||||
} catch (RequestContentException $e) {
|
||||
$this->miscService->log(
|
||||
'Error while managing request: ' . json_encode($request) . ' ' . $e->getMessage(), 1
|
||||
);
|
||||
$this->queueService->deleteRequest($queue);
|
||||
$this->requestQueueService->deleteRequest($queue);
|
||||
} catch (RequestResultSizeException $e) {
|
||||
$this->miscService->log(
|
||||
'Error while managing request: ' . json_encode($request) . ' ' . $e->getMessage(), 1
|
||||
);
|
||||
$this->queueService->deleteRequest($queue);
|
||||
$this->requestQueueService->deleteRequest($queue);
|
||||
} catch (RequestServerException $e) {
|
||||
$this->miscService->log(
|
||||
'Temporary error while managing request: RequestServerException - ' . json_encode(
|
||||
|
@ -291,7 +291,7 @@ class ActivityService {
|
|||
) . ' - '
|
||||
. $e->getMessage(), 1
|
||||
);
|
||||
$this->queueService->endRequest($queue, false);
|
||||
$this->requestQueueService->endRequest($queue, false);
|
||||
$this->failInstances[] = $host;
|
||||
} catch (RequestNetworkException $e) {
|
||||
$this->miscService->log(
|
||||
|
@ -299,7 +299,7 @@ class ActivityService {
|
|||
$request
|
||||
) . ' - ' . $e->getMessage(), 1
|
||||
);
|
||||
$this->queueService->endRequest($queue, false);
|
||||
$this->requestQueueService->endRequest($queue, false);
|
||||
$this->failInstances[] = $host;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class CurlService {
|
|||
use TPathTools;
|
||||
|
||||
|
||||
const ASYNC_TOKEN = '/async/token/{token}';
|
||||
const ASYNC_REQUEST_TOKEN = '/async/request/{token}';
|
||||
const USER_AGENT = 'Nextcloud Social';
|
||||
|
||||
|
||||
|
@ -237,7 +237,7 @@ class CurlService {
|
|||
$parse = parse_url($address);
|
||||
$host = $this->get('host', $parse, '');
|
||||
$path = $this->withEndSlash($this->get('path', $parse, '')) . $this->withoutBeginSlash(
|
||||
self::ASYNC_TOKEN
|
||||
self::ASYNC_REQUEST_TOKEN
|
||||
);
|
||||
$path = str_replace('{token}', $token, $path);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ use OCA\Social\Model\InstancePath;
|
|||
use OCA\Social\Model\RequestQueue;
|
||||
|
||||
|
||||
class QueueService {
|
||||
class RequestQueueService {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
@ -58,7 +58,7 @@ class QueueService {
|
|||
|
||||
|
||||
/**
|
||||
* QueueService constructor.
|
||||
* RequestQueueService constructor.
|
||||
*
|
||||
* @param RequestQueueRequest $requestQueueRequest
|
||||
* @param ConfigService $configService
|
Ładowanie…
Reference in New Issue