lab5: брокер RabbitMQ, worker и асинхронная обработка
This commit is contained in:
@@ -60,7 +60,8 @@ WITH claim AS (
|
||||
SELECT 1 FROM chat_members WHERE chat_id = $7::uuid AND user_id = $1
|
||||
)
|
||||
AND (SELECT count(*) FROM attachments a
|
||||
WHERE a.chat_id = $7::uuid AND a.status = 'ready'
|
||||
WHERE a.chat_id = $7::uuid
|
||||
AND a.status IN ('queued','processing','ready')
|
||||
AND a.id = ANY($8::uuid[])) = cardinality($8::uuid[])
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING response_body
|
||||
|
||||
@@ -97,12 +97,15 @@ export class MessagesService {
|
||||
// чужую заявку сняли между нашими двумя запросами (503).
|
||||
if (!(await this.idempotency.isMember(chatId, currentUser.id)))
|
||||
throw new NotFoundException();
|
||||
// Unknown, foreign-chat or unfinished attachment: not found.
|
||||
if (
|
||||
ids.length > 0 &&
|
||||
!(await this.attachments.allLinkable(chatId, ids))
|
||||
)
|
||||
throw new NotFoundException();
|
||||
// Unknown or foreign-chat ids are 404; an attachment whose
|
||||
// processing failed is a conflict, not a missing object.
|
||||
const linkState =
|
||||
ids.length > 0
|
||||
? await this.attachments.linkState(chatId, ids)
|
||||
: 'ok';
|
||||
if (linkState === 'failed')
|
||||
throw new ConflictException('Attachment processing failed');
|
||||
if (linkState === 'missing') throw new NotFoundException();
|
||||
this.metrics.increment('idempotency.claim_lost');
|
||||
throw new ServiceUnavailableException(
|
||||
'Idempotency key could not be claimed',
|
||||
|
||||
Reference in New Issue
Block a user