@plusscommunities/pluss-maintenance-aws 2.1.45 → 2.1.46

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.
Files changed (44) hide show
  1. package/createJob.js +201 -114
  2. package/createJobType.js +49 -49
  3. package/db/maintenance/addMaintenanceJob.js +100 -90
  4. package/db/maintenance/editMaintenanceJob.js +22 -12
  5. package/db/maintenance/getJobEmail.js +22 -22
  6. package/deleteJob.js +58 -58
  7. package/deleteJobType.js +40 -40
  8. package/editJob.js +126 -65
  9. package/editJobStatus.js +57 -57
  10. package/editJobType.js +61 -61
  11. package/editNote.js +117 -117
  12. package/feature.config.js +279 -270
  13. package/getData.js +48 -41
  14. package/getJob.js +4 -4
  15. package/getJobType.js +35 -35
  16. package/getJobTypes.js +66 -66
  17. package/getJobs.js +48 -48
  18. package/integration/IntegrationStrategy.js +52 -52
  19. package/integration/archibus/ArchibusStrategy.js +42 -28
  20. package/integration/index.js +19 -19
  21. package/jobChanged.js +88 -89
  22. package/jobTypesChanged.js +52 -39
  23. package/package.json +3 -3
  24. package/requests/assignRequest.js +81 -81
  25. package/requests/getAssignees.js +27 -27
  26. package/requests/getExternalSync.js +100 -100
  27. package/requests/getPropertyRequests.js +89 -0
  28. package/requests/getRequest.js +77 -77
  29. package/requests/helper/hasRequestPermission.js +12 -12
  30. package/requests/helper/isValidAssignee.js +10 -10
  31. package/requests/retrySync.js +90 -90
  32. package/requests/setExternalJobId.js +113 -113
  33. package/requests/updatePriority.js +33 -33
  34. package/scheduleJobImport.js +63 -63
  35. package/sendJobEmail.js +105 -104
  36. package/updateData.js +34 -34
  37. package/values.config.a.js +26 -25
  38. package/values.config.default.js +30 -28
  39. package/values.config.enquiry.js +222 -221
  40. package/values.config.feedback.js +194 -193
  41. package/values.config.food.js +29 -28
  42. package/values.config.forms.js +29 -28
  43. package/values.config.js +30 -28
  44. package/watchJobs.js +154 -154
@@ -20,30 +20,30 @@ const { getStrategy } = require("../integration");
20
20
  * @returns {Promise<boolean>} True if the job has already been synced
21
21
  */
22
22
  const isAlreadySynced = async (job, logId) => {
23
- const history = job.history || [];
24
- const hasSuccessfulSync = history.some(
25
- (entry) => entry.EntryType === "ExternalIDSet"
26
- );
23
+ const history = job.history || [];
24
+ const hasSuccessfulSync = history.some(
25
+ (entry) => entry.EntryType === "ExternalIDSet",
26
+ );
27
27
 
28
- if (hasSuccessfulSync) {
29
- log("isAlreadySynced", "FoundInHistory", true, logId);
30
- return true;
31
- }
28
+ if (hasSuccessfulSync) {
29
+ log("isAlreadySynced", "FoundInHistory", true, logId);
30
+ return true;
31
+ }
32
32
 
33
- try {
34
- const integrationStrategy = await getStrategy(job.site);
35
- if (integrationStrategy.getExternalId) {
36
- const externalId = await integrationStrategy.getExternalId(job);
37
- if (externalId) {
38
- log("isAlreadySynced", "FoundViaStrategy", externalId, logId);
39
- return true;
40
- }
41
- }
42
- } catch (error) {
43
- log("isAlreadySynced", "StrategyCheckError", error.message, logId);
44
- }
33
+ try {
34
+ const integrationStrategy = await getStrategy(job.site);
35
+ if (integrationStrategy.getExternalId) {
36
+ const externalId = await integrationStrategy.getExternalId(job);
37
+ if (externalId) {
38
+ log("isAlreadySynced", "FoundViaStrategy", externalId, logId);
39
+ return true;
40
+ }
41
+ }
42
+ } catch (error) {
43
+ log("isAlreadySynced", "StrategyCheckError", error.message, logId);
44
+ }
45
45
 
46
- return false;
46
+ return false;
47
47
  };
48
48
 
49
49
  /**
@@ -80,82 +80,82 @@ const isAlreadySynced = async (job, logId) => {
80
80
  * // 500 - Internal error
81
81
  */
82
82
  module.exports = async (event, data) => {
83
- const action = "retrySync";
84
- const logId = log(action, "Input", data);
83
+ const action = "retrySync";
84
+ const logId = log(action, "Input", data);
85
85
 
86
- try {
87
- // Validate required fields
88
- if (!data.id) {
89
- return {
90
- status: 422,
91
- data: { error: "Missing required field: id" },
92
- };
93
- }
86
+ try {
87
+ // Validate required fields
88
+ if (!data.id) {
89
+ return {
90
+ status: 422,
91
+ data: { error: "Missing required field: id" },
92
+ };
93
+ }
94
94
 
95
- // Fetch the job record
96
- let job;
97
- try {
98
- job = await getRef(values.tableNameMaintenance, "id", data.id);
99
- } catch (error) {
100
- log(action, "Error:JobNotFound", { error: error.message }, logId);
101
- return { status: 404, data: { error: "Job not found" } };
102
- }
95
+ // Fetch the job record
96
+ let job;
97
+ try {
98
+ job = await getRef(values.tableNameMaintenance, "id", data.id);
99
+ } catch (error) {
100
+ log(action, "Error:JobNotFound", { error: error.message }, logId);
101
+ return { status: 404, data: { error: "Job not found" } };
102
+ }
103
103
 
104
- if (!job) {
105
- log(action, "JobNotFound", { id: data.id }, logId);
106
- return { status: 404, data: { error: "Job not found" } };
107
- }
104
+ if (!job) {
105
+ log(action, "JobNotFound", { id: data.id }, logId);
106
+ return { status: 404, data: { error: "Job not found" } };
107
+ }
108
108
 
109
- // Validate user has permission to manage maintenance for this site
110
- const authorised = await validateMasterAuth(
111
- event,
112
- values.permissionMaintenanceTracking,
113
- job.site
114
- );
109
+ // Validate user has permission to manage maintenance for this site
110
+ const authorised = await validateMasterAuth(
111
+ event,
112
+ values.permissionMaintenanceTracking,
113
+ job.site,
114
+ );
115
115
 
116
- if (!authorised) {
117
- log(action, "NotAuthorised", { site: job.site }, logId);
118
- return { status: 403, data: { error: "Not authorised" } };
119
- }
116
+ if (!authorised) {
117
+ log(action, "NotAuthorised", { site: job.site }, logId);
118
+ return { status: 403, data: { error: "Not authorised" } };
119
+ }
120
120
 
121
- // Prevent duplicate syncs - check if already synced via history or external entity
122
- const alreadySynced = await isAlreadySynced(job, logId);
123
- if (alreadySynced) {
124
- log(action, "AlreadySynced", { id: job.id }, logId);
125
- return {
126
- status: 400,
127
- data: { error: "Job already synced to external system" },
128
- };
129
- }
121
+ // Prevent duplicate syncs - check if already synced via history or external entity
122
+ const alreadySynced = await isAlreadySynced(job, logId);
123
+ if (alreadySynced) {
124
+ log(action, "AlreadySynced", { id: job.id }, logId);
125
+ return {
126
+ status: 400,
127
+ data: { error: "Job already synced to external system" },
128
+ };
129
+ }
130
130
 
131
- // Set ExtCreateRetry to a new timestamp value.
132
- // The jobChanged stream handler detects this field change and
133
- // triggers pushRequestToIntegration() to retry the external sync.
134
- const retryTimestamp = moment.utc().valueOf();
135
- const updatedJob = await editRef(
136
- values.tableNameMaintenance,
137
- "id",
138
- job.id,
139
- {
140
- ExtCreateRetry: retryTimestamp,
141
- }
142
- );
131
+ // Set ExtCreateRetry to a new timestamp value.
132
+ // The jobChanged stream handler detects this field change and
133
+ // triggers pushRequestToIntegration() to retry the external sync.
134
+ const retryTimestamp = moment.utc().valueOf();
135
+ const updatedJob = await editRef(
136
+ values.tableNameMaintenance,
137
+ "id",
138
+ job.id,
139
+ {
140
+ ExtCreateRetry: retryTimestamp,
141
+ },
142
+ );
143
143
 
144
- log(action, "RetryTriggered", { ExtCreateRetry: retryTimestamp }, logId);
144
+ log(action, "RetryTriggered", { ExtCreateRetry: retryTimestamp }, logId);
145
145
 
146
- return {
147
- status: 200,
148
- data: {
149
- success: true,
150
- message: "Sync retry initiated. Check back shortly for results.",
151
- job: updatedJob,
152
- },
153
- };
154
- } catch (error) {
155
- log(action, "InternalError", error, logId);
156
- return {
157
- status: 500,
158
- data: { error: "Internal error", message: error.message },
159
- };
160
- }
146
+ return {
147
+ status: 200,
148
+ data: {
149
+ success: true,
150
+ message: "Sync retry initiated. Check back shortly for results.",
151
+ job: updatedJob,
152
+ },
153
+ };
154
+ } catch (error) {
155
+ log(action, "InternalError", error, logId);
156
+ return {
157
+ status: 500,
158
+ data: { error: "Internal error", message: error.message },
159
+ };
160
+ }
161
161
  };
@@ -8,117 +8,117 @@ const { values } = require("../values.config");
8
8
  const { log } = require("@plusscommunities/pluss-core-aws/helper");
9
9
 
10
10
  module.exports = async (event, data) => {
11
- const action = "setExternalJobId";
12
- const logId = log(action, "Input", data);
13
-
14
- try {
15
- // 1. Validate required fields
16
- if (!data.id || !data.externalId || !data.systemType) {
17
- return {
18
- status: 422,
19
- data: {
20
- error: "Missing required fields: id, externalId, systemType",
21
- },
22
- };
23
- }
24
-
25
- // 2. Find the job by ID (UUID)
26
- let job;
27
-
28
- try {
29
- job = await getRef(values.tableNameMaintenance, "id", data.id);
30
- } catch (error) {
31
- log(action, "Error:JobNotFound", { error: error.message }, logId);
32
- return { status: 404, data: { error: "Job not found" } };
33
- }
34
-
35
- if (!job) {
36
- log(action, "JobNotFound", { id: data.id }, logId);
37
- return { status: 404, data: { error: "Job not found" } };
38
- }
39
-
40
- // 3. Validate authorization using the job's site
41
- const authorised = await validateMasterAuth(
42
- event,
43
- values.permissionMaintenanceTracking,
44
- job.site
45
- );
46
-
47
- if (!authorised) {
48
- log(action, "NotAuthorised", { site: job.site }, logId);
49
- return { status: 403, data: { error: "Not authorised" } };
50
- }
51
-
52
- // 4. Get user preview for history tracking
53
- const user = await getUserPreviewFromReq(event);
54
-
55
- // 5. Create entity type identifier
56
- const entityType = `${values.serviceKey}_${data.systemType}`;
57
- const rowId = `${entityType}_${data.externalId}`;
58
-
59
- log(action, "CreatingExternalEntity", { entityType, rowId }, logId);
60
-
61
- // 6. Create/update external entity mapping
62
- const externalEntity = await updateRef("externalentities", {
63
- RowId: rowId,
64
- EntityType: entityType,
65
- ActiveEntityType: entityType,
66
- InternalId: job.id,
67
- ExternalId: data.externalId,
68
- LastUpdated: moment().valueOf(),
69
- TrackedData: data.trackedData || {},
70
- Site: job.site, // Store for site-specific queries
71
- SystemType: data.systemType,
72
- });
73
-
74
- log(action, "ExternalEntityCreated", externalEntity, logId);
75
-
76
- // 7. Add history entry
77
- if (!job.history) job.history = [];
78
- job.history.push({
79
- timestamp: moment.utc().valueOf(),
80
- EntryType: "ExternalIDSet",
81
- externalId: data.externalId,
82
- user,
83
- systemType: data.systemType,
84
- });
85
-
86
- // 8. Update job with history and optionally update job number for system parity
87
- let updatedJob = job;
88
-
89
- if (!isNaN(data.externalId)) {
90
- log(
91
- action,
92
- "UpdatingJobNumber",
93
- {
94
- oldJobNo: job.jobNo,
95
- newJobNo: data.externalId,
96
- },
97
- logId
98
- );
99
-
100
- updatedJob = await editRef(values.tableNameMaintenance, "id", job.id, {
101
- jobNo: Number(data.externalId),
102
- jobId: Number(data.externalId) + "",
103
- history: job.history,
104
- });
105
-
106
- log(action, "JobNumberUpdated", updatedJob, logId);
107
- }
108
-
109
- return {
110
- status: 200,
111
- data: {
112
- success: true,
113
- job: updatedJob,
114
- externalEntity: externalEntity,
115
- },
116
- };
117
- } catch (error) {
118
- log(action, "InternalError", error, logId);
119
- return {
120
- status: 500,
121
- data: { error: "Internal error", message: error.message },
122
- };
123
- }
11
+ const action = "setExternalJobId";
12
+ const logId = log(action, "Input", data);
13
+
14
+ try {
15
+ // 1. Validate required fields
16
+ if (!data.id || !data.externalId || !data.systemType) {
17
+ return {
18
+ status: 422,
19
+ data: {
20
+ error: "Missing required fields: id, externalId, systemType",
21
+ },
22
+ };
23
+ }
24
+
25
+ // 2. Find the job by ID (UUID)
26
+ let job;
27
+
28
+ try {
29
+ job = await getRef(values.tableNameMaintenance, "id", data.id);
30
+ } catch (error) {
31
+ log(action, "Error:JobNotFound", { error: error.message }, logId);
32
+ return { status: 404, data: { error: "Job not found" } };
33
+ }
34
+
35
+ if (!job) {
36
+ log(action, "JobNotFound", { id: data.id }, logId);
37
+ return { status: 404, data: { error: "Job not found" } };
38
+ }
39
+
40
+ // 3. Validate authorization using the job's site
41
+ const authorised = await validateMasterAuth(
42
+ event,
43
+ values.permissionMaintenanceTracking,
44
+ job.site,
45
+ );
46
+
47
+ if (!authorised) {
48
+ log(action, "NotAuthorised", { site: job.site }, logId);
49
+ return { status: 403, data: { error: "Not authorised" } };
50
+ }
51
+
52
+ // 4. Get user preview for history tracking
53
+ const user = await getUserPreviewFromReq(event);
54
+
55
+ // 5. Create entity type identifier
56
+ const entityType = `${values.serviceKey}_${data.systemType}`;
57
+ const rowId = `${entityType}_${data.externalId}`;
58
+
59
+ log(action, "CreatingExternalEntity", { entityType, rowId }, logId);
60
+
61
+ // 6. Create/update external entity mapping
62
+ const externalEntity = await updateRef("externalentities", {
63
+ RowId: rowId,
64
+ EntityType: entityType,
65
+ ActiveEntityType: entityType,
66
+ InternalId: job.id,
67
+ ExternalId: data.externalId,
68
+ LastUpdated: moment().valueOf(),
69
+ TrackedData: data.trackedData || {},
70
+ Site: job.site, // Store for site-specific queries
71
+ SystemType: data.systemType,
72
+ });
73
+
74
+ log(action, "ExternalEntityCreated", externalEntity, logId);
75
+
76
+ // 7. Add history entry
77
+ if (!job.history) job.history = [];
78
+ job.history.push({
79
+ timestamp: moment.utc().valueOf(),
80
+ EntryType: "ExternalIDSet",
81
+ externalId: data.externalId,
82
+ user,
83
+ systemType: data.systemType,
84
+ });
85
+
86
+ // 8. Update job with history and optionally update job number for system parity
87
+ let updatedJob = job;
88
+
89
+ if (!isNaN(data.externalId)) {
90
+ log(
91
+ action,
92
+ "UpdatingJobNumber",
93
+ {
94
+ oldJobNo: job.jobNo,
95
+ newJobNo: data.externalId,
96
+ },
97
+ logId,
98
+ );
99
+
100
+ updatedJob = await editRef(values.tableNameMaintenance, "id", job.id, {
101
+ jobNo: Number(data.externalId),
102
+ jobId: Number(data.externalId) + "",
103
+ history: job.history,
104
+ });
105
+
106
+ log(action, "JobNumberUpdated", updatedJob, logId);
107
+ }
108
+
109
+ return {
110
+ status: 200,
111
+ data: {
112
+ success: true,
113
+ job: updatedJob,
114
+ externalEntity: externalEntity,
115
+ },
116
+ };
117
+ } catch (error) {
118
+ log(action, "InternalError", error, logId);
119
+ return {
120
+ status: 500,
121
+ data: { error: "Internal error", message: error.message },
122
+ };
123
+ }
124
124
  };
@@ -6,41 +6,41 @@ const { log } = require("@plusscommunities/pluss-core-aws/helper");
6
6
  const { values } = require("../values.config");
7
7
 
8
8
  module.exports = async (event, data) => {
9
- const logId = log("updatePriority", "data", data);
10
- // check required data
11
- const requiredKeys = ["id", "priority"];
12
- if (!data || requiredKeys.some((prop) => !data.hasOwnProperty(prop))) {
13
- log("updatePriority", "InsufficientInput", 422, logId);
14
- return { status: 422, data: { error: "Insufficient input" } };
15
- }
9
+ const logId = log("updatePriority", "data", data);
10
+ // check required data
11
+ const requiredKeys = ["id", "priority"];
12
+ if (!data || requiredKeys.some((prop) => !data.hasOwnProperty(prop))) {
13
+ log("updatePriority", "InsufficientInput", 422, logId);
14
+ return { status: 422, data: { error: "Insufficient input" } };
15
+ }
16
16
 
17
- const job = await getRef(values.tableNameMaintenance, "id", data.id);
18
- log("updatePriority", "job", job, logId);
19
- log("updatePriority", "site", job.site, logId);
17
+ const job = await getRef(values.tableNameMaintenance, "id", data.id);
18
+ log("updatePriority", "job", job, logId);
19
+ log("updatePriority", "site", job.site, logId);
20
20
 
21
- // validate authorisation
22
- const valid = await validateMasterAuth(
23
- event,
24
- values.permissionMaintenanceTracking,
25
- job.site
26
- );
27
- log("updatePriority", "valid", valid, logId);
28
- if (!valid) {
29
- const validAssignee = await isValidAssignee(
30
- event,
31
- job.site,
32
- job.AssigneeId
33
- );
34
- log("updatePriority", "validAssignee", validAssignee, logId);
35
- if (!validAssignee) {
36
- log("updatePriority", "NotAuthorised", 403, logId);
37
- return { status: 403, data: { error: "Not authorised" } };
38
- }
39
- }
21
+ // validate authorisation
22
+ const valid = await validateMasterAuth(
23
+ event,
24
+ values.permissionMaintenanceTracking,
25
+ job.site,
26
+ );
27
+ log("updatePriority", "valid", valid, logId);
28
+ if (!valid) {
29
+ const validAssignee = await isValidAssignee(
30
+ event,
31
+ job.site,
32
+ job.AssigneeId,
33
+ );
34
+ log("updatePriority", "validAssignee", validAssignee, logId);
35
+ if (!validAssignee) {
36
+ log("updatePriority", "NotAuthorised", 403, logId);
37
+ return { status: 403, data: { error: "Not authorised" } };
38
+ }
39
+ }
40
40
 
41
- job.priority = data.priority;
42
- const result = await editMaintenanceJob(job);
41
+ job.priority = data.priority;
42
+ const result = await editMaintenanceJob(job);
43
43
 
44
- log("updatePriority", "result", result, logId);
45
- return { status: 200, data: { job: result } };
44
+ log("updatePriority", "result", result, logId);
45
+ return { status: 200, data: { job: result } };
46
46
  };
@@ -5,83 +5,83 @@ const { getStrategy } = require("./integration");
5
5
  const { log } = require("@plusscommunities/pluss-core-aws/helper");
6
6
 
7
7
  const processSingle = async (strategy, item) => {
8
- // use IDs to refresh request data
9
- const logId = log("processSingle", "RefreshFromSource", item.ExternalId);
8
+ // use IDs to refresh request data
9
+ const logId = log("processSingle", "RefreshFromSource", item.ExternalId);
10
10
 
11
- // refresh from external source
12
- await strategy.refreshFromSource(
13
- item.InternalId,
14
- item.ExternalId,
15
- item.TrackedData
16
- );
11
+ // refresh from external source
12
+ await strategy.refreshFromSource(
13
+ item.InternalId,
14
+ item.ExternalId,
15
+ item.TrackedData,
16
+ );
17
17
 
18
- // save updated timestamp
19
- await editRef("externalentities", "RowId", item.RowId, {
20
- LastUpdated: moment().valueOf(),
21
- });
18
+ // save updated timestamp
19
+ await editRef("externalentities", "RowId", item.RowId, {
20
+ LastUpdated: moment().valueOf(),
21
+ });
22
22
 
23
- log("processBatch", "Refreshed", item.ExternalId, logId);
24
- return true;
23
+ log("processBatch", "Refreshed", item.ExternalId, logId);
24
+ return true;
25
25
  };
26
26
 
27
27
  const processBatch = async (strategy, startTime) => {
28
- const logId = log("processBatch", "StartTime", moment().valueOf());
28
+ const logId = log("processBatch", "StartTime", moment().valueOf());
29
29
 
30
- // use index query to fetch IDs of requests
31
- const query = {
32
- IndexName: "ActiveEntityTypeIndex",
33
- KeyConditionExpression:
34
- "ActiveEntityType = :activeEntityType AND LastUpdated < :lastUpdate", // only fetch items that haven't been updated in this scan
35
- ExpressionAttributeValues: {
36
- ":activeEntityType": strategy.getEntityType(),
37
- ":lastUpdate": startTime - strategy.getRefreshInterval(),
38
- },
39
- Limit: 10,
40
- ScanIndexForward: false,
41
- };
42
- const { Items } = await indexQuery("externalentities", query);
30
+ // use index query to fetch IDs of requests
31
+ const query = {
32
+ IndexName: "ActiveEntityTypeIndex",
33
+ KeyConditionExpression:
34
+ "ActiveEntityType = :activeEntityType AND LastUpdated < :lastUpdate", // only fetch items that haven't been updated in this scan
35
+ ExpressionAttributeValues: {
36
+ ":activeEntityType": strategy.getEntityType(),
37
+ ":lastUpdate": startTime - strategy.getRefreshInterval(),
38
+ },
39
+ Limit: 10,
40
+ ScanIndexForward: false,
41
+ };
42
+ const { Items } = await indexQuery("externalentities", query);
43
43
 
44
- const promises = [];
44
+ const promises = [];
45
45
 
46
- Items.forEach((item) => {
47
- log("processBatch", "ProcessSingle", JSON.stringify(item), logId);
48
- promises.push(processSingle(strategy, JSON.parse(JSON.stringify(item))));
49
- });
46
+ Items.forEach((item) => {
47
+ log("processBatch", "ProcessSingle", JSON.stringify(item), logId);
48
+ promises.push(processSingle(strategy, JSON.parse(JSON.stringify(item))));
49
+ });
50
50
 
51
- await Promise.all(promises);
52
- log("processBatch", "EndOfBatch", Items.length, logId);
53
- return Items.length;
51
+ await Promise.all(promises);
52
+ log("processBatch", "EndOfBatch", Items.length, logId);
53
+ return Items.length;
54
54
  };
55
55
 
56
56
  module.exports.scheduleJobImport = async (event, context, callback) => {
57
- const logId = log("scheduleJobImport", "Start", true);
58
- // get active integration
59
- const integrationStrategy = await getStrategy("plussSpace");
60
- if (!integrationStrategy.isValidIntegration()) {
61
- log("scheduleJobImport", "Exit", "No valid integration", logId);
62
- return;
63
- }
57
+ const logId = log("scheduleJobImport", "Start", true);
58
+ // get active integration
59
+ const integrationStrategy = await getStrategy("plussSpace");
60
+ if (!integrationStrategy.isValidIntegration()) {
61
+ log("scheduleJobImport", "Exit", "No valid integration", logId);
62
+ return;
63
+ }
64
64
 
65
- const startTime = moment().valueOf();
66
- const timeout = 3 * 60 * 1000; // 3 minutes
67
- let noneToProcess = false;
68
- log("scheduleJobImport", "StartTime", startTime, logId);
65
+ const startTime = moment().valueOf();
66
+ const timeout = 3 * 60 * 1000; // 3 minutes
67
+ let noneToProcess = false;
68
+ log("scheduleJobImport", "StartTime", startTime, logId);
69
69
 
70
- while (!noneToProcess && moment().valueOf() < startTime + timeout) {
71
- const logId = log("scheduleJobImport", "StartLoop", moment().valueOf());
72
- const count = await processBatch(integrationStrategy, startTime);
73
- log("scheduleJobImport", "Count", count, logId);
74
- if (!count) {
75
- log("scheduleJobImport", "noneToProcess", true, logId);
76
- noneToProcess = true;
77
- }
78
- log("scheduleJobImport", "EndLoop", moment().valueOf(), logId);
79
- }
80
- // TODO: Remove this call once all existing records have ActiveEntityType (PC-1382)
81
- const remainingTime = (startTime + timeout) - moment().valueOf();
82
- if (remainingTime > 0) {
83
- await integrationStrategy.backfillActiveEntityType(remainingTime);
84
- }
70
+ while (!noneToProcess && moment().valueOf() < startTime + timeout) {
71
+ const logId = log("scheduleJobImport", "StartLoop", moment().valueOf());
72
+ const count = await processBatch(integrationStrategy, startTime);
73
+ log("scheduleJobImport", "Count", count, logId);
74
+ if (!count) {
75
+ log("scheduleJobImport", "noneToProcess", true, logId);
76
+ noneToProcess = true;
77
+ }
78
+ log("scheduleJobImport", "EndLoop", moment().valueOf(), logId);
79
+ }
80
+ // TODO: Remove this call once all existing records have ActiveEntityType (PC-1382)
81
+ const remainingTime = startTime + timeout - moment().valueOf();
82
+ if (remainingTime > 0) {
83
+ await integrationStrategy.backfillActiveEntityType(remainingTime);
84
+ }
85
85
 
86
- log("scheduleJobImport", "End", moment().valueOf(), logId);
86
+ log("scheduleJobImport", "End", moment().valueOf(), logId);
87
87
  };