Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(data): sync processor fixes #11262

Merged
merged 9 commits into from
Apr 21, 2023
34 changes: 25 additions & 9 deletions packages/datastore/src/sync/processors/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,23 +357,39 @@ class SyncProcessor {
await Promise.all(promises);

do {
/**
* It's possible that the running processes have been closed
david-mcafee marked this conversation as resolved.
Show resolved Hide resolved
* (e.g. `DataStore.clear` has been called)
*/
if (!this.runningProcesses.isOpen) {
return;
logger.error(
'No open running processes when starting sync'
david-mcafee marked this conversation as resolved.
Show resolved Hide resolved
);
return res();
}

const limit = Math.min(
maxRecordsToSync - recordsReceived,
syncPageSize
);

({ items, nextToken, startedAt } = await this.retrievePage(
modelDefinition,
lastSync,
nextToken,
limit,
filter,
onTerminate
));
/**
* It's possible that retrievePage will error here, for instance,
* during `authModeRetry` if there are no open running processes.
* An example would be if a model does not exist in the schema.
*/
david-mcafee marked this conversation as resolved.
Show resolved Hide resolved
try {
({ items, nextToken, startedAt } = await this.retrievePage(
modelDefinition,
lastSync,
nextToken,
limit,
filter,
onTerminate
));
} catch (error) {
logger.error('Error retrieving page:', error);
david-mcafee marked this conversation as resolved.
Show resolved Hide resolved
}

recordsReceived += items.length;

Expand Down