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

Async Batch Processing #791

Merged
merged 1 commit into from
Nov 22, 2024
Merged

Async Batch Processing #791

merged 1 commit into from
Nov 22, 2024

Conversation

ejscribner
Copy link
Collaborator

resolves #790

Added an artificial delay to createManyCallback() to validate:

Screen.Recording.2024-11-22.at.11.23.33.AM.mov
Code w/ Delay (replace `createManyCallback()` with the below) ``` export const createManyCallback = ( document: ModelTypes, metadata: ModelMetadata, extra: any, options: saveOptions = {}, ): Promise => { const Model = metadata.ottoman.getModel(metadata.modelName);

// Function to introduce a delay
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

// Artificial delay before calling Model.create
const artificialDelay = 2000; // Delay in milliseconds (e.g., 1000ms = 1 second)

return delay(artificialDelay)
.then(() => Model.create(document, options))
.then((created) => {
console.log(Successfully wrote document at ${new Date().toISOString()});
return Promise.resolve(new StatusExecution(created, 'SUCCESS'));
})
.catch((error) => {
/* istanbul ignore next */
return Promise.reject(new StatusExecution(document, 'FAILURE', error.constructor.name, error.message));
});
};

</details>

Copy link
Contributor

@thejcfactor thejcfactor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ejscribner ejscribner merged commit dd616ed into master Nov 22, 2024
1 check passed
@ejscribner ejscribner deleted the bug-790/async-batch-processing branch November 22, 2024 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asynchronous Batch Processing
2 participants