2018-11-28 18:18:37 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2018-11-28 18:18:37 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-09-08 13:46:22 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-11-28 18:18:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Cron;
|
|
|
|
|
|
|
|
use OCA\Social\Exceptions\SocialAppConfigException;
|
|
|
|
use OCA\Social\Service\ActivityService;
|
2019-01-24 11:24:17 +00:00
|
|
|
use OCA\Social\Service\RequestQueueService;
|
2019-01-25 11:54:22 +00:00
|
|
|
use OCA\Social\Service\StreamQueueService;
|
2018-11-28 18:18:37 +00:00
|
|
|
use OCP\AppFramework\QueryException;
|
2023-05-25 20:45:28 +00:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\BackgroundJob\TimedJob;
|
2018-11-28 18:18:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Queue
|
|
|
|
*
|
|
|
|
* @package OCA\Social\Cron
|
|
|
|
*/
|
|
|
|
class Queue extends TimedJob {
|
2022-05-11 16:22:54 +00:00
|
|
|
private ActivityService $activityService;
|
|
|
|
private RequestQueueService $requestQueueService;
|
|
|
|
private StreamQueueService $streamQueueService;
|
2018-11-28 18:18:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache constructor.
|
|
|
|
*/
|
2022-05-11 16:22:54 +00:00
|
|
|
public function __construct(ITimeFactory $time, RequestQueueService $requestQueueService, StreamQueueService $streamQueueService, ActivityService $activityService) {
|
2022-04-15 11:34:01 +00:00
|
|
|
parent::__construct($time);
|
2018-11-28 18:18:37 +00:00
|
|
|
$this->setInterval(12 * 60); // 12 minutes
|
2022-05-11 16:22:54 +00:00
|
|
|
$this->requestQueueService = $requestQueueService;
|
|
|
|
$this->streamQueueService = $streamQueueService;
|
|
|
|
$this->activityService = $activityService;
|
2018-11-28 18:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $argument
|
|
|
|
*
|
|
|
|
* @throws QueryException
|
|
|
|
*/
|
|
|
|
protected function run($argument) {
|
2019-01-25 11:54:22 +00:00
|
|
|
$this->manageRequestQueue();
|
|
|
|
$this->manageStreamQueue();
|
2018-11-28 18:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-17 09:12:27 +00:00
|
|
|
/**
|
|
|
|
*/
|
2019-01-25 11:54:22 +00:00
|
|
|
private function manageRequestQueue() {
|
|
|
|
$requests = $this->requestQueueService->getRequestStandby();
|
2018-11-28 20:21:28 +00:00
|
|
|
$this->activityService->manageInit();
|
2018-11-28 18:18:37 +00:00
|
|
|
|
|
|
|
foreach ($requests as $request) {
|
2018-12-04 10:58:00 +00:00
|
|
|
$request->setTimeout(ActivityService::TIMEOUT_SERVICE);
|
2018-11-28 18:18:37 +00:00
|
|
|
try {
|
|
|
|
$this->activityService->manageRequest($request);
|
|
|
|
} catch (SocialAppConfigException $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 11:54:22 +00:00
|
|
|
|
|
|
|
private function manageStreamQueue() {
|
2019-05-27 10:19:54 +00:00
|
|
|
$total = 0;
|
2019-01-25 11:54:22 +00:00
|
|
|
$items = $this->streamQueueService->getRequestStandby($total);
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$this->streamQueueService->manageStreamQueue($item);
|
|
|
|
}
|
|
|
|
}
|
2018-11-28 18:18:37 +00:00
|
|
|
}
|