Verified Commit a77e3118 authored by aguestuser's avatar aguestuser
Browse files

[WIP][EMERGENCY ONLY] batch all messages

* this is a branch to merge into master and deploy in case our
  hypothesis in MR !179 (that only messages with attachments need to
  be batched in order to avoid rate limit errors) proves false
* in case of emergency:
  * merge this MR
  * pull master locally
  * run `make m.deploy`
parent 89c46674
......@@ -134,19 +134,15 @@ const handleCommandResult = async ({ commandResult, dispatchable }) => {
// Dispatchable -> Promise<MessageCount>
const broadcast = async ({ db, sock, channel, sdMessage }) => {
const recipients = channel.memberships.map(m => m.memberPhoneNumber)
try {
if (isEmpty(sdMessage.attachments)) {
await signal.broadcastMessage(sock, recipients, addHeader({ channel, sdMessage }))
} else {
const recipientBatches = batchesOfN(recipients, broadcastBatchSize)
await sequence(
recipientBatches.map(recipientBatch => () =>
signal.broadcastMessage(sock, recipientBatch, addHeader({ channel, sdMessage })),
),
broadcastBatchInterval,
)
}
const recipientBatches = batchesOfN(recipients, broadcastBatchSize)
await sequence(
recipientBatches.map(recipientBatch => () =>
signal.broadcastMessage(sock, recipientBatch, addHeader({ channel, sdMessage })),
),
broadcastBatchInterval,
)
return messageCountRepository.countBroadcast(db, channel)
} catch (e) {
logger.error(e)
......
......@@ -201,7 +201,7 @@ describe('messenger service', () => {
})
})
describe('when message has attachments', () => {
describe('when message has no attachments', () => {
const noAttachmentSdMessage = { ...sdMessage, attachments: [] }
beforeEach(
async () =>
......@@ -221,8 +221,10 @@ describe('messenger service', () => {
}),
)
it('sends all messages without batching', () => {
expect(broadcastMessageStub.callCount).to.eql(1)
it('sends all messages in batches', () => {
expect(broadcastMessageStub.callCount).to.eql(
[...adminPhoneNumbers, ...subscriberPhoneNumbers].length / broadcastBatchSize,
)
})
it('it increments the broadcast count for the channel exactly once', () => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment