Handle different pending failures

This commit is contained in:
Eric Bailey
2024-05-15 16:56:31 -05:00
parent 9dd837ceab
commit 02692225e3
+14 -4
View File
@@ -288,6 +288,7 @@ export class Convo {
if (this.convo) { if (this.convo) {
this.status = ConvoStatus.Ready this.status = ConvoStatus.Ready
this.refreshConvo() this.refreshConvo()
this.batchRetryPendingMessages()
} else { } else {
this.status = ConvoStatus.Initializing this.status = ConvoStatus.Initializing
this.setup() this.setup()
@@ -841,15 +842,26 @@ export class Convo {
} }
async batchRetryPendingMessages() { async batchRetryPendingMessages() {
if (this.pendingMessageFailure === 'unrecoverable') return
// reset if present, and recoverable
if (this.pendingMessageFailure === 'recoverable') {
this.pendingMessageFailure = null
this.commit()
}
const messageArray = Array.from(this.pendingMessages.values())
if (messageArray.length === 0) return
logger.debug( logger.debug(
`Convo: retrying ${this.pendingMessages.size} pending messages`, `Convo: batch retrying ${this.pendingMessages.size} pending messages`,
{}, {},
logger.DebugContext.convo, logger.DebugContext.convo,
) )
try { try {
// throw new Error('UNCOMMENT TO TEST RETRY') // throw new Error('UNCOMMENT TO TEST RETRY')
const messageArray = Array.from(this.pendingMessages.values())
const {data} = await networkRetry(2, () => { const {data} = await networkRetry(2, () => {
return this.agent.api.chat.bsky.convo.sendMessageBatch( return this.agent.api.chat.bsky.convo.sendMessageBatch(
{ {
@@ -990,8 +1002,6 @@ export class Convo {
retry: retry:
this.pendingMessageFailure === 'recoverable' this.pendingMessageFailure === 'recoverable'
? () => { ? () => {
this.pendingMessageFailure = null
this.commit()
this.batchRetryPendingMessages() this.batchRetryPendingMessages()
} }
: undefined, : undefined,