Skip to content

Commit

Permalink
limit concurrency of role assign to 10 calls
Browse files Browse the repository at this point in the history
  • Loading branch information
williammck committed May 12, 2023
1 parent 421ddc8 commit 5cf0c80
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
8 changes: 6 additions & 2 deletions assign_roles.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const pLimit = require('p-limit');

const limit = pLimit(10);

async function assignRoles(member) {
const MANAGED_ROLES = ["Supervisor", "Administrator", "New Member", "PPL", "IR", "CMEL", "ATPL", "Flight Instructor", "Flight Examiner", "No Military Rating", "M1", "M2","M3","M4"];
const discordCidResponse = await fetch(`https://apiv2-dev.vatsim.net/v2/members/discord/${member.user.id}`).catch(error => console.trace(error));
Expand Down Expand Up @@ -73,5 +77,5 @@ async function assignRoles(member) {
}

module.exports = {
assignRoles: assignRoles
}
assignRoles: (member) => limit(() => assignRoles(member))
}
43 changes: 41 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"dependencies": {
"discord.js": "^14.6.0",
"dotenv": "^16.0.3",
"nodemon": "^2.0.20"
"nodemon": "^2.0.20",
"p-limit": "^3.1.0"
},
"scripts": {
"start": "node bot.js",
Expand Down

0 comments on commit 5cf0c80

Please sign in to comment.