to avoid conflict, filters failing instance when processing queue

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/70/head
Maxence Lange 2018-11-28 19:21:28 -01:00
rodzic df2e2715d0
commit 8b9217292d
6 zmienionych plików z 23 dodań i 16 usunięć

Wyświetl plik

@ -109,11 +109,11 @@ class QueueProcess extends Base {
return; return;
} }
$this->activityService->manageInit();
foreach ($requests as $request) { foreach ($requests as $request) {
$output->write('.'); $output->write('.');
try { try {
$this->activityService->manageRequest($request); $this->activityService->manageRequest($request);
} catch (ActorDoesNotExistException $e) {
} catch (RequestException $e) { } catch (RequestException $e) {
} catch (SocialAppConfigException $e) { } catch (SocialAppConfigException $e) {
} }

Wyświetl plik

@ -98,10 +98,10 @@ class QueueController extends Controller {
$this->async(); $this->async();
$requests = $this->queueService->getRequestFromToken($token, RequestQueue::STATUS_STANDBY); $requests = $this->queueService->getRequestFromToken($token, RequestQueue::STATUS_STANDBY);
$this->activityService->manageInit();
foreach ($requests as $request) { foreach ($requests as $request) {
try { try {
$this->activityService->manageRequest($request); $this->activityService->manageRequest($request);
} catch (ActorDoesNotExistException $e) {
} catch (RequestException $e) { } catch (RequestException $e) {
} catch (SocialAppConfigException $e) { } catch (SocialAppConfigException $e) {
} }

Wyświetl plik

@ -93,11 +93,11 @@ class Queue extends TimedJob {
private function manageQueue() { private function manageQueue() {
$requests = $this->queueService->getRequestStandby($total = 0); $requests = $this->queueService->getRequestStandby($total = 0);
$this->activityService->manageInit();
foreach ($requests as $request) { foreach ($requests as $request) {
try { try {
$this->activityService->manageRequest($request); $this->activityService->manageRequest($request);
} catch (ActorDoesNotExistException $e) {
} catch (RequestException $e) { } catch (RequestException $e) {
} catch (SocialAppConfigException $e) { } catch (SocialAppConfigException $e) {
} }

Wyświetl plik

@ -361,15 +361,6 @@ class CoreRequestBuilder {
} }
/**
* @param IQueryBuilder $qb
* @param string $order
*/
protected function orderByPriority(IQueryBuilder &$qb, string $order = 'desc') {
$qb->orderBy('priority', $order);
}
/** /**
* @param IQueryBuilder $qb * @param IQueryBuilder $qb
* @param string $field * @param string $field

Wyświetl plik

@ -86,14 +86,14 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
/** /**
* return Queue from database based on the status != 9 * return Queue from database based on the status=0
* *
* @return RequestQueue[] * @return RequestQueue[]
*/ */
public function getStandby(): array { public function getStandby(): array {
$qb = $this->getQueueSelectSql(); $qb = $this->getQueueSelectSql();
$this->limitToStatus($qb, RequestQueue::STATUS_STANDBY); $this->limitToStatus($qb, RequestQueue::STATUS_STANDBY);
$this->orderByPriority($qb, 'desc'); $qb->orderBy('id', 'asc');
$requests = []; $requests = [];
$cursor = $qb->execute(); $cursor = $qb->execute();
@ -122,7 +122,7 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
$this->limitToStatus($qb, $status); $this->limitToStatus($qb, $status);
} }
$this->orderByPriority($qb); $qb->orderBy('priority', 'desc');
$requests = []; $requests = [];
$cursor = $qb->execute(); $cursor = $qb->execute();

Wyświetl plik

@ -107,6 +107,10 @@ class ActivityService {
private $miscService; private $miscService;
/** @var array */
private $failInstances;
/** /**
* ActivityService constructor. * ActivityService constructor.
* *
@ -233,10 +237,12 @@ class ActivityService {
$author = $this->getAuthorFromItem($activity); $author = $this->getAuthorFromItem($activity);
$instancePaths = $this->generateInstancePaths($activity); $instancePaths = $this->generateInstancePaths($activity);
$token = $this->queueService->generateRequestQueue($instancePaths, $activity, $author); $token = $this->queueService->generateRequestQueue($instancePaths, $activity, $author);
$this->manageInit();
try { try {
$directRequest = $this->queueService->getPriorityRequest($token); $directRequest = $this->queueService->getPriorityRequest($token);
$this->manageRequest($directRequest); $this->manageRequest($directRequest);
} catch (RequestException $e) {
} catch (NoHighPriorityRequestException $e) { } catch (NoHighPriorityRequestException $e) {
} catch (EmptyQueueException $e) { } catch (EmptyQueueException $e) {
return ''; return '';
@ -248,6 +254,11 @@ class ActivityService {
} }
public function manageInit() {
$this->failInstances = [];
}
/** /**
* @param RequestQueue $queue * @param RequestQueue $queue
* *
@ -255,6 +266,11 @@ class ActivityService {
* @throws SocialAppConfigException * @throws SocialAppConfigException
*/ */
public function manageRequest(RequestQueue $queue) { public function manageRequest(RequestQueue $queue) {
$host = $queue->getInstance()
->getAddress();
if (in_array($host, $this->failInstances)) {
throw new RequestException();
}
try { try {
$this->queueService->initRequest($queue); $this->queueService->initRequest($queue);
@ -262,7 +278,6 @@ class ActivityService {
return; return;
} }
try { try {
$result = $this->generateRequest( $result = $this->generateRequest(
$queue->getInstance(), $queue->getActivity(), $queue->getAuthor() $queue->getInstance(), $queue->getActivity(), $queue->getAuthor()
@ -278,6 +293,7 @@ class ActivityService {
$this->queueService->endRequest($queue, true); $this->queueService->endRequest($queue, true);
} else { } else {
$this->queueService->endRequest($queue, false); $this->queueService->endRequest($queue, false);
$this->failInstances[] = $host;
} }
} catch (QueueStatusException $e) { } catch (QueueStatusException $e) {
} }