Retry metadata transfer for reminders, see if it fixes Sentry 363208698

This commit is contained in:
Ben Gotow 2018-02-04 20:14:02 -08:00
parent 438705c9dc
commit d50d17d63f
3 changed files with 17 additions and 3 deletions

View file

@ -80,9 +80,15 @@ export async function updateDraftReminderMetadata(draftSession, metadataValue) {
}
export async function transferReminderMetadataFromDraftToThread({ accountId, headerMessageId }) {
const message = await DatabaseStore.findBy(Message, { accountId, headerMessageId });
let message = await DatabaseStore.findBy(Message, { accountId, headerMessageId });
if (!message) {
throw new Error('SendReminders: Could not find message to update');
// The task has just completed, wait a moment to see if the message appears. Testing to
// see whether this resolves https://sentry.io/foundry-376-llc/mailspring/issues/363208698/
await Promise.delay(1500);
message = await DatabaseStore.findBy(Message, { accountId, headerMessageId });
if (!message) {
throw new Error('SendReminders: Could not find message to update');
}
}
const metadata = message.metadataForPluginId(PLUGIN_ID) || {};
@ -91,6 +97,9 @@ export async function transferReminderMetadataFromDraftToThread({ accountId, hea
}
const thread = await DatabaseStore.find(Thread, message.threadId);
if (!thread) {
throw new Error('SendReminders: Could not find thread to update');
}
updateReminderMetadata(thread, {
expiration: metadata.expiration,
sentHeaderMessageId: metadata.sentHeaderMessageId,

View file

@ -284,7 +284,7 @@ class DatabaseStore extends MailspringStore {
// We don't want to unnecessarily defer and delay every single query,
// so we only set the timer when we are actually backing off for a
// retry.
await new Promise(resolve => setTimeout(resolve, scheduler.currentDelay()));
await Promise.delay(scheduler.currentDelay());
}
let stmt = this._preparedStatementCache.get(query);

View file

@ -112,6 +112,10 @@ async function each(items, fn) {
return results;
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function props(obj) {
const awaitables = [];
const keys = Object.keys(obj);
@ -149,6 +153,7 @@ global.Promise.prototype.isResolved = isResolved;
global.Promise.prototype.isRejected = isRejected;
global.Promise.each = each;
global.Promise.delay = delay;
global.Promise.props = props;
global.Promise.promisify = promisify;
global.Promise.promisifyAll = promisifyAll;