Skip to content
Open
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
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"qs": "^6.10.5"
},
"name": "shotgun-nodejs",
"version": "4.4.0",
"version": "4.5.0",
"description": "Autodesk Shotgrid REST API library",
"main": "src/index.js",
"devDependencies": {
Expand Down
23 changes: 23 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ const { RequestError } = require('./error');
const DEFAULT_API_BASE_PATH = '/api/v1';
const RETRY_COUNT = 2;

/**
* Shotgun API Client
* @class
* @property {string} siteUrl - The base URL for the Shotgun site
* @property {Object} credentials - Authentication credentials
* @property {boolean} debug - Enable debug logging
* @property {string} apiBasePath - Base path for API endpoints
* @property {Function} [onAfterSleepSetup] - Testing hook called after retry delay is scheduled.
* Signature: function({ attemptNumber: number }): void
* Purpose: Allows tests with fake timers to advance time after async-retry schedules setTimeout.
* This should only be set in test environments to control retry timing with fake timers.
*/
class ShotgunApiClient {

constructor({ siteUrl, credentials, debug, apiBasePath = DEFAULT_API_BASE_PATH }) {
Expand Down Expand Up @@ -204,6 +216,17 @@ class ShotgunApiClient {
},
{
retries: RETRY_COUNT,
onRetry: async (err, attemptNumber) => {
// Testing hook: allows tests with fake timers to advance time after retry delay
// is scheduled by async-retry. We yield control with Promise.resolve() to ensure
// async-retry's setTimeout is registered before the test advances the clock.
// Example usage in tests:
// client.onAfterSleepSetup = () => { this.clock.next(); };
if (this.onAfterSleepSetup) {
Comment thread
souphan-adsk marked this conversation as resolved.
await Promise.resolve(); // Let async-retry set up setTimeout first
this.onAfterSleepSetup({ attemptNumber });
}
}
}
);
}
Expand Down