@sasjs/adapter 4.10.0 → 4.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -84,5 +84,5 @@
84
84
  "https": "1.0.0",
85
85
  "tough-cookie": "4.1.3"
86
86
  },
87
- "version": "4.10.0"
87
+ "version": "4.10.1"
88
88
  }
@@ -223,7 +223,7 @@ const needsRetry = (state: string) =>
223
223
  * @param authConfig - an access token, refresh token, client and secret for an authorized user.
224
224
  * @param streamLog - indicates if job log should be streamed.
225
225
  * @param logStream - job log stream.
226
- * @param jobSessionManager - job session object containing session object and an instance of Session Manager. Job session object is used to periodically (every 10th job state poll) check parent session state.
226
+ * @param jobSessionManager - job session object containing session object and an instance of Session Manager. Job session object is used to periodically (every 10th job state poll) check parent session state. Session state is considered healthy if it is equal to 'running' or 'idle'.
227
227
  * @returns - a promise which resolves with a job state
228
228
  */
229
229
  export const doPoll = async (
@@ -263,15 +263,20 @@ export const doPoll = async (
263
263
  throw new JobStatePollError(jobId, err)
264
264
  })
265
265
 
266
+ // Checks if session state is equal to 'running' or 'idle'.
267
+ const isSessionStatesHealthy = (state: string) =>
268
+ [SessionState.Running, SessionState.Idle].includes(
269
+ state as SessionState
270
+ )
271
+
266
272
  // Clear parent session and throw an error if session state is not
267
- // 'running' or response status is not 200.
268
- if (sessionState !== SessionState.Running || responseStatus !== 200) {
273
+ // 'running', 'idle' or response status is not 200.
274
+ if (!isSessionStatesHealthy(sessionState) || responseStatus !== 200) {
269
275
  sessionManager.clearSession(sessionId, access_token)
270
276
 
271
- const sessionError =
272
- sessionState !== SessionState.Running
273
- ? `Session state of the job is not 'running'. Session state is '${sessionState}'`
274
- : `Session response status is not 200. Session response status is ${responseStatus}.`
277
+ const sessionError = isSessionStatesHealthy(sessionState)
278
+ ? `Session response status is not 200. Session response status is ${responseStatus}.`
279
+ : `Session state of the job is not 'running' or 'idle'. Session state is '${sessionState}'`
275
280
 
276
281
  throw new JobStatePollError(jobId, new Error(sessionError))
277
282
  }