From 620a8d9c7fa2d5f70ae32e1af498d30e5f038f67 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 19 Oct 2022 11:22:38 +0100 Subject: [PATCH] Add debugging for unsent to-device messages --- src/ToDeviceMessageQueue.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ToDeviceMessageQueue.ts b/src/ToDeviceMessageQueue.ts index aaff912de..709021505 100644 --- a/src/ToDeviceMessageQueue.ts +++ b/src/ToDeviceMessageQueue.ts @@ -48,14 +48,18 @@ export class ToDeviceMessageQueue { public async queueBatch(batch: ToDeviceBatch): Promise { const batches: ToDeviceBatchWithTxnId[] = []; for (let i = 0; i < batch.batch.length; i += MAX_BATCH_SIZE) { - batches.push({ + const batchWithTxnId = { eventType: batch.eventType, batch: batch.batch.slice(i, i + MAX_BATCH_SIZE), txnId: this.client.makeTxnId(), - }); + }; + batches.push(batchWithTxnId); + const recips = batchWithTxnId.batch.map((msg) => `${msg.userId}:${msg.deviceId}`); + logger.info(`Created batch of to-device messages with txn id ${batchWithTxnId.txnId} for ${recips}`); } await this.client.store.saveToDeviceBatches(batches); + logger.info(`Enqueued to-device messages with txn ids ${batches.map((batch) => batch.txnId)}`); this.sendQueue(); } @@ -118,7 +122,9 @@ export class ToDeviceMessageQueue { contentMap[item.userId][item.deviceId] = item.payload; } - logger.info(`Sending batch of ${batch.batch.length} to-device messages with ID ${batch.id}`); + logger.info( + `Sending batch of ${batch.batch.length} to-device messages with ID ${batch.id} and txnId ${batch.txnId}`, + ); await this.client.sendToDevice(batch.eventType, contentMap, batch.txnId); }