Ensured that delivery time is never after the deadline

This commit is contained in:
Chris Raible 2024-08-28 22:18:50 -07:00
parent ff1beb1f26
commit d83d7ef621

View File

@ -380,7 +380,7 @@ class BatchSendingService {
// Calculate the target delivery time for the batch
const timeRemaining = deadline.getTime() - lastDeliveryTime.getTime();
const targetDeliveryDelay = Math.abs(timeRemaining / (queue.length + 1));
const targetDeliveryTime = new Date(lastDeliveryTime.getTime() + targetDeliveryDelay);
const targetDeliveryTime = new Date(Math.min(lastDeliveryTime.getTime() + targetDeliveryDelay, deadline.getTime()));
batchData.deliveryTime = targetDeliveryTime;
lastDeliveryTime = targetDeliveryTime;
}