Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fileignoreconfig:
ignore_detectors:
- filecontent
- filename: package-lock.json
checksum: c37956b0e6ccd5267dac7fd6f4347fbb5ad41defe1c42d39aaaeaf64d2cf8605
checksum: 0c7d422e080dc20d4bac85d403f05cbb32bcf81789ccf52eb13306eb68d5b96d
- filename: .husky/pre-commit
checksum: 52a664f536cf5d1be0bea19cb6031ca6e8107b45b6314fe7d47b7fad7d800632
- filename: test/sanity-check/api/user-test.js
Expand Down
21 changes: 14 additions & 7 deletions lib/core/concurrency-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const defaultConfig = {
retryOnHttpServerError: true,
maxNetworkRetries: 3,
networkRetryDelay: 100, // Base delay for network retries (ms)
networkBackoffStrategy: 'exponential' // 'exponential' or 'fixed'
networkBackoffStrategy: 'exponential', // 'exponential' or 'fixed'
delayMs: null // Delay in milliseconds before making each request
}

export function ConcurrencyQueue ({ axios, config }) {
Expand Down Expand Up @@ -175,16 +176,22 @@ export function ConcurrencyQueue ({ axios, config }) {

// Initial shift will check running request,
// and adds request to running queue if max requests are not running
this.initialShift = () => {
this.initialShift = async () => {
if (this.running.length < this.config.maxRequests && !this.paused) {
shift()
await shift()
}
}

// INTERNAL: Shift the queued item to running queue
const shift = () => {
const shift = async () => {
if (this.queue.length && !this.paused) {
const queueItem = this.queue.shift()

// Add configurable delay before making the request if specified
if (this.config.delayMs && this.config.delayMs > 0) {
await new Promise(resolve => setTimeout(resolve, this.config.delayMs))
}

queueItem.resolve(queueItem.request)
this.running.push(queueItem)
}
Expand All @@ -197,7 +204,7 @@ export function ConcurrencyQueue ({ axios, config }) {

this.push = requestPromise => {
this.queue.push(requestPromise)
this.initialShift()
this.initialShift().catch(console.error)
}

this.clear = () => {
Expand Down Expand Up @@ -312,7 +319,7 @@ export function ConcurrencyQueue ({ axios, config }) {
return refreshToken()
} else {
for (let i = 0; i < this.config.maxRequests; i++) {
this.initialShift()
this.initialShift().catch(console.error)
}
}
}, time))
Expand Down Expand Up @@ -360,7 +367,7 @@ export function ConcurrencyQueue ({ axios, config }) {
}
})
for (let i = 0; i < this.config.maxRequests; i++) {
this.initialShift()
this.initialShift().catch(console.error)
}
})
}
Expand Down
10 changes: 6 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.25.0",
"version": "1.25.1",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down Expand Up @@ -53,7 +53,7 @@
"license": "MIT",
"dependencies": {
"assert": "^2.1.0",
"axios": "^1.11.0",
"axios": "^1.12.2",
"buffer": "^6.0.3",
"form-data": "^4.0.4",
"husky": "^9.1.7",
Expand Down
1 change: 1 addition & 0 deletions types/contentstackClient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface ContentstackConfig extends AxiosRequestConfig, ContentstackToke
logHandler?: (level: string, data: any) => void
application?: string
integration?: string
delayMs?: number
}

export interface LoginDetails {
Expand Down
Loading