Problem: I have a list of users to delete. Not only the user himself is deleted, but also a significant amount of data associated with him. Some tables that are involved in deleting user information contain millions of records. All internal processes are started asynchronously when deleted. And if, when deleting one user, there are no problems, and all processes in the background are successful (that is, the client does not expect a response), then if you run several of them, this takes all the server resources, which naturally negatively affects the work of the site as long as it goes removal.
for (let i = 0; i < users.length; i++) {
const user = users[i];
await this.removeInstance(user, removedBy);
}
this.removeInstance contains many other asynchronous operations.
What I want: start an asynchronous operation this.removeInstance at 3 minute intervals. The speed of data deletion is not important to me, but according to my observations 1-2 minutes is exactly enough to "completely finish" with one user.
Note: this.removeInstance return removed user, but I cannot use this, since a dozen processes are already running in the background to clear his information.
Thanks for any help!