Defer unprocessed item attempt update

This commit is contained in:
Fedor Indutny 2021-09-17 16:11:24 -07:00 committed by GitHub
parent 7b5faa1cc1
commit b83c00f43f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 55 deletions

View file

@ -706,30 +706,14 @@ export default class MessageReceiver
const items = await this.storage.protocol.getAllUnprocessed();
log.info('getAllFromCache loaded', items.length, 'saved envelopes');
return Promise.all(
map(items, async item => {
const attempts = 1 + (item.attempts || 0);
return items.map(item => {
const { attempts = 0 } = item;
try {
if (attempts >= 3) {
log.warn('getAllFromCache final attempt for envelope', item.id);
await this.storage.protocol.removeUnprocessed(item.id);
} else {
await this.storage.protocol.updateUnprocessedAttempts(
item.id,
attempts
);
}
} catch (error) {
log.error(
'getAllFromCache error updating item after load:',
Errors.toLogFormat(error)
);
}
return item;
})
);
return {
...item,
attempts: attempts + 1,
};
});
}
private async decryptAndCacheBatch(