Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add retries to all handlers (#3935)

authored by

Eric Bailey and committed by
GitHub
55fdbc73 becc708c

+90 -73
+67 -55
src/state/messages/convo/agent.ts
··· 7 7 } from '@atproto-labs/api' 8 8 import {nanoid} from 'nanoid/non-secure' 9 9 10 + import {networkRetry} from '#/lib/async/retry' 10 11 import {logger} from '#/logger' 11 12 import {isNative} from '#/platform/detection' 12 13 import { ··· 459 460 recipients: AppBskyActorDefs.ProfileViewBasic[] 460 461 }>(async (resolve, reject) => { 461 462 try { 462 - const response = await this.agent.api.chat.bsky.convo.getConvo( 463 - { 464 - convoId: this.convoId, 465 - }, 466 - { 467 - headers: { 468 - Authorization: this.__tempFromUserDid, 463 + const response = await networkRetry(2, () => { 464 + return this.agent.api.chat.bsky.convo.getConvo( 465 + { 466 + convoId: this.convoId, 469 467 }, 470 - }, 471 - ) 468 + { 469 + headers: { 470 + Authorization: this.__tempFromUserDid, 471 + }, 472 + }, 473 + ) 474 + }) 472 475 473 476 const convo = response.data.convo 474 477 ··· 544 547 // throw new Error('UNCOMMENT TO TEST RETRY') 545 548 } 546 549 547 - const response = await this.agent.api.chat.bsky.convo.getMessages( 548 - { 549 - cursor: this.oldestRev, 550 - convoId: this.convoId, 551 - limit: isNative ? 25 : 50, 552 - }, 553 - { 554 - headers: { 555 - Authorization: this.__tempFromUserDid, 550 + const nextCursor = this.oldestRev // for TS 551 + const response = await networkRetry(2, () => { 552 + return this.agent.api.chat.bsky.convo.getMessages( 553 + { 554 + cursor: nextCursor, 555 + convoId: this.convoId, 556 + limit: isNative ? 40 : 60, 557 + }, 558 + { 559 + headers: { 560 + Authorization: this.__tempFromUserDid, 561 + }, 556 562 }, 557 - }, 558 - ) 563 + ) 564 + }) 559 565 const {cursor, messages} = response.data 560 566 561 567 this.oldestRev = cursor ?? null ··· 736 742 // throw new Error('UNCOMMENT TO TEST RETRY') 737 743 const {id, message} = pendingMessage 738 744 739 - const response = await this.agent.api.chat.bsky.convo.sendMessage( 740 - { 741 - convoId: this.convoId, 742 - message, 743 - }, 744 - { 745 - encoding: 'application/json', 746 - headers: { 747 - Authorization: this.__tempFromUserDid, 745 + const response = await networkRetry(2, () => { 746 + return this.agent.api.chat.bsky.convo.sendMessage( 747 + { 748 + convoId: this.convoId, 749 + message, 750 + }, 751 + { 752 + encoding: 'application/json', 753 + headers: { 754 + Authorization: this.__tempFromUserDid, 755 + }, 748 756 }, 749 - }, 750 - ) 757 + ) 758 + }) 751 759 const res = response.data 752 760 753 761 /* ··· 786 794 787 795 try { 788 796 const messageArray = Array.from(this.pendingMessages.values()) 789 - const {data} = await this.agent.api.chat.bsky.convo.sendMessageBatch( 790 - { 791 - items: messageArray.map(({message}) => ({ 792 - convoId: this.convoId, 793 - message, 794 - })), 795 - }, 796 - { 797 - encoding: 'application/json', 798 - headers: { 799 - Authorization: this.__tempFromUserDid, 797 + const {data} = await networkRetry(2, () => { 798 + return this.agent.api.chat.bsky.convo.sendMessageBatch( 799 + { 800 + items: messageArray.map(({message}) => ({ 801 + convoId: this.convoId, 802 + message, 803 + })), 800 804 }, 801 - }, 802 - ) 805 + { 806 + encoding: 'application/json', 807 + headers: { 808 + Authorization: this.__tempFromUserDid, 809 + }, 810 + }, 811 + ) 812 + }) 803 813 const {items} = data 804 814 805 815 /* ··· 838 848 this.commit() 839 849 840 850 try { 841 - await this.agent.api.chat.bsky.convo.deleteMessageForSelf( 842 - { 843 - convoId: this.convoId, 844 - messageId, 845 - }, 846 - { 847 - encoding: 'application/json', 848 - headers: { 849 - Authorization: this.__tempFromUserDid, 851 + await networkRetry(2, () => { 852 + return this.agent.api.chat.bsky.convo.deleteMessageForSelf( 853 + { 854 + convoId: this.convoId, 855 + messageId, 850 856 }, 851 - }, 852 - ) 857 + { 858 + encoding: 'application/json', 859 + headers: { 860 + Authorization: this.__tempFromUserDid, 861 + }, 862 + }, 863 + ) 864 + }) 853 865 } catch (e) { 854 866 this.deletedMessages.delete(messageId) 855 867 this.commit()
+23 -18
src/state/messages/events/agent.ts
··· 2 2 import EventEmitter from 'eventemitter3' 3 3 import {nanoid} from 'nanoid/non-secure' 4 4 5 + import {networkRetry} from '#/lib/async/retry' 5 6 import {logger} from '#/logger' 6 7 import {DEFAULT_POLL_INTERVAL} from '#/state/messages/events/const' 7 8 import { ··· 265 266 logger.debug(`${LOGGER_CONTEXT}: init`, {}, logger.DebugContext.convo) 266 267 267 268 try { 268 - const response = await this.agent.api.chat.bsky.convo.listConvos( 269 - { 270 - limit: 1, 271 - }, 272 - { 273 - headers: { 274 - Authorization: this.__tempFromUserDid, 269 + const response = await networkRetry(2, () => { 270 + return this.agent.api.chat.bsky.convo.listConvos( 271 + { 272 + limit: 1, 275 273 }, 276 - }, 277 - ) 274 + { 275 + headers: { 276 + Authorization: this.__tempFromUserDid, 277 + }, 278 + }, 279 + ) 280 + }) 278 281 // throw new Error('UNCOMMENT TO TEST INIT FAILURE') 279 282 280 283 const {convos} = response.data ··· 358 361 // ) 359 362 360 363 try { 361 - const response = await this.agent.api.chat.bsky.convo.getLog( 362 - { 363 - cursor: this.latestRev, 364 - }, 365 - { 366 - headers: { 367 - Authorization: this.__tempFromUserDid, 364 + const response = await networkRetry(2, () => { 365 + return this.agent.api.chat.bsky.convo.getLog( 366 + { 367 + cursor: this.latestRev, 368 368 }, 369 - }, 370 - ) 369 + { 370 + headers: { 371 + Authorization: this.__tempFromUserDid, 372 + }, 373 + }, 374 + ) 375 + }) 371 376 372 377 // throw new Error('UNCOMMENT TO TEST POLL FAILURE') 373 378