@getjones/test-infra 2.5.0 → 2.6.0
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 +1 -1
- package/src/common/commonFlows/records/records.js +2 -2
- package/src/saas/internal-api/accounts/api/core/accounts.core.service.js +1 -1
- package/src/saas/internal-api/requirements/api/requirements.api.js +1 -1
- package/src/saas/internal-api/requirements/api/requirements.service.js +4 -4
- package/src/saas/internal-api/thread-scheduler/runner.js +29 -3
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ const updateInviteDate = async function(recordId, inviteDate, context) {
|
|
|
22
22
|
throw new Error('Record invite date could not be updated', updateResponse);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const threadSchedulerResponse = await threadScheduler.
|
|
25
|
+
const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
|
|
26
26
|
|
|
27
27
|
if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
|
|
28
28
|
throw new Error('Thread scheduler has failed to run', threadSchedulerResponse);
|
|
@@ -46,7 +46,7 @@ const updatePolicyExpiryDateForRecord = async function(recordId, expiryDate, pol
|
|
|
46
46
|
throw new Error('Record expiry date could not be updated', updateResponse);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const threadSchedulerResponse = await threadScheduler.
|
|
49
|
+
const threadSchedulerResponse = await threadScheduler.runForRecords([recordId]);
|
|
50
50
|
|
|
51
51
|
if (threadSchedulerResponse.status !== httpResponseStatusCodes.OK) {
|
|
52
52
|
throw new Error('Thread scheduler has failed to run', threadSchedulerResponse);
|
|
@@ -41,7 +41,7 @@ const getOrCreateAccount = async (createAccountModel, context) => {
|
|
|
41
41
|
const response = await accountsAPI.create(createAccountModel, context);
|
|
42
42
|
|
|
43
43
|
if (!response.data) {
|
|
44
|
-
throw new Error(`Account by the name ${createAccountModel.companyName}
|
|
44
|
+
throw new Error(`Account by the name ${createAccountModel.companyName} was not created`);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
return response.data;
|
|
@@ -19,7 +19,7 @@ const getRequirementsByTabId = (tabId, context) => {
|
|
|
19
19
|
return requests.getRequestHandler(Endpoints.getRequirementsByTabId, { tabId }, context);
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const getRequirementById = (requirementId, context, isPermanentLink =
|
|
22
|
+
const getRequirementById = (requirementId, context, { isPermanentLink } = {}) => {
|
|
23
23
|
return requests.getRequestHandler(Endpoints.getRequirementById(requirementId), { isPermanentLink }, context);
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -14,11 +14,11 @@ const getRequirementsByTabId = (tabId, context) => {
|
|
|
14
14
|
return requirementsAPI.getRequirementsByTabId(tabId, context);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const getRequirementById = (requirementId, context, isPermanentLink =
|
|
18
|
-
return requirementsAPI.getRequirementById(requirementId, context, isPermanentLink);
|
|
17
|
+
const getRequirementById = (requirementId, context, { isPermanentLink } = {}) => {
|
|
18
|
+
return requirementsAPI.getRequirementById(requirementId, context, { isPermanentLink });
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const getRequirementByName = async (tabId, requirementName, context, isPermanentLink =
|
|
21
|
+
const getRequirementByName = async (tabId, requirementName, context, { isPermanentLink } = {}) => {
|
|
22
22
|
const { data: requirementList } = await getRequirementsByTabId(tabId, context);
|
|
23
23
|
|
|
24
24
|
const requirement = requirementList.find(req => req.name === requirementName);
|
|
@@ -27,7 +27,7 @@ const getRequirementByName = async (tabId, requirementName, context, isPermanent
|
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const requirementResponse = await getRequirementById(requirement.id, context, isPermanentLink);
|
|
30
|
+
const requirementResponse = await getRequirementById(requirement.id, context, { isPermanentLink });
|
|
31
31
|
return requirementResponse.data.requirement;
|
|
32
32
|
};
|
|
33
33
|
|
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
const requests = require('../../internal-api/../../common/requests/cookieAuth/requests');
|
|
2
|
+
const httpResponseStatusCodes = require('../../../common/httpResponseStatusCodes.json');
|
|
3
|
+
const timeUtils = require('../../../common/utils/timeUtils');
|
|
4
|
+
|
|
2
5
|
const { backendUrl, threadSchedulerSecret } = require('../../../env').getEnv();
|
|
3
6
|
|
|
4
7
|
const Endpoints = {
|
|
5
8
|
run: `${backendUrl}/threadSchedular/${threadSchedulerSecret}`
|
|
6
9
|
};
|
|
7
10
|
|
|
8
|
-
const runThreadScheduler = ({ contractorIds = [], scheduledReportsIds = [] } = {}) => {
|
|
11
|
+
const runThreadScheduler = async ({ contractorIds = [], scheduledReportsIds = [], retries = 10 } = {}) => {
|
|
9
12
|
const params = { contractorIdsList: contractorIds.toString(), scheduledReportsIds: scheduledReportsIds.toString() };
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
let response;
|
|
15
|
+
while (!response || isOverloadError(response.status) && retries--) {
|
|
16
|
+
response = await requests.getRequestHandler(Endpoints.run, params);
|
|
17
|
+
await timeUtils.waitFor(1.5).seconds;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (response.status !== httpResponseStatusCodes.OK) {
|
|
21
|
+
throw new Error('Thread scheduler has failed to run', response);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return response;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
runForRecords: function(contractorIds) {
|
|
29
|
+
return runThreadScheduler({ contractorIds });
|
|
30
|
+
},
|
|
31
|
+
runForReports: function(scheduledReportsIds) {
|
|
32
|
+
return runThreadScheduler({ scheduledReportsIds });
|
|
33
|
+
}
|
|
11
34
|
};
|
|
12
35
|
|
|
13
|
-
|
|
36
|
+
function isOverloadError(errorCode) {
|
|
37
|
+
const overloadResponseErrors = [httpResponseStatusCodes.TOO_MANY_REQUESTS, httpResponseStatusCodes.CONFLICT];
|
|
38
|
+
return overloadResponseErrors.includes(errorCode);
|
|
39
|
+
}
|