sr-npm 1.7.108 → 1.7.109
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/backend/collectionConsts.js +1 -1
- package/backend/consts.js +25 -61
- package/backend/data.js +36 -3
- package/backend/fetchPositionsFromSRAPI.js +1 -1
- package/package.json +1 -1
package/backend/consts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {saveJobsDataToCMS,saveJobsDescriptionsAndLocationApplyUrlToCMS,aggregateJobsByFieldToCMS,referenceJobsToField,createApiKeyCollectionAndFillIt} = require('./data');
|
|
1
|
+
const {saveJobsDataToCMS,saveJobsDescriptionsAndLocationApplyUrlToCMS,aggregateJobsByFieldToCMS,referenceJobsToField,createApiKeyCollectionAndFillIt,createCollections,aggregateJobs,referenceJobs} = require('./data');
|
|
2
2
|
const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
|
|
3
3
|
const { COLLECTIONS, COLLECTIONS_FIELDS, JOBS_COLLECTION_FIELDS } = require('./collectionConsts');
|
|
4
4
|
|
|
@@ -8,13 +8,9 @@ const TASKS_NAMES = {
|
|
|
8
8
|
SYNC_JOBS: 'syncJobsFromSRAPIToCMS',
|
|
9
9
|
INSERT_JOBS_TO_CMS: 'insertJobsToCMS',
|
|
10
10
|
INSERT_JOBS_DESCRIPTIONS_LOCATION_APPLY_URL_TO_CMS: 'insertJobsDescriptionsLocationApplyUrlToCMS',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
REFERENCE_JOBS_TO_DEPARTMENT: 'referenceJobsToDepartment',
|
|
15
|
-
CREATE_JOBS_COLLECTION: 'createJobsCollection',
|
|
16
|
-
CREATE_CITIES_COLLECTION: 'createCitiesCollection',
|
|
17
|
-
CREATE_AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION: 'createAmountOfJobsPerDepartmentCollection',
|
|
11
|
+
AGGREGATE_JOBS_BY_FIELD_TO_CMS: 'aggregateJobsByFieldToCMS',
|
|
12
|
+
REFERENCE_JOBS: 'referenceJobs',
|
|
13
|
+
CREATE_COLLECTIONS: 'createCollections',
|
|
18
14
|
CREATE_API_KEY_COLLECTION_AND_FILL_IT: 'createApiKeyCollectionAndFillIt',
|
|
19
15
|
}
|
|
20
16
|
|
|
@@ -23,39 +19,21 @@ const TASKS = {
|
|
|
23
19
|
[TASKS_NAMES.SYNC_JOBS]: {
|
|
24
20
|
name: TASKS_NAMES.SYNC_JOBS,
|
|
25
21
|
childTasks: [
|
|
26
|
-
{ name: TASKS_NAMES.
|
|
27
|
-
{ name: TASKS_NAMES.CREATE_CITIES_COLLECTION },
|
|
28
|
-
{name: TASKS_NAMES.CREATE_AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION},
|
|
22
|
+
{ name: TASKS_NAMES.CREATE_COLLECTIONS},
|
|
29
23
|
{ name: TASKS_NAMES.INSERT_JOBS_TO_CMS },
|
|
30
24
|
{ name: TASKS_NAMES.INSERT_JOBS_DESCRIPTIONS_LOCATION_APPLY_URL_TO_CMS },
|
|
31
|
-
{ name: TASKS_NAMES.
|
|
32
|
-
{
|
|
33
|
-
{ name: TASKS_NAMES.REFERENCE_JOBS_TO_LOCATIONS },
|
|
34
|
-
{ name: TASKS_NAMES.REFERENCE_JOBS_TO_DEPARTMENT },
|
|
25
|
+
{ name: TASKS_NAMES.AGGREGATE_JOBS_BY_FIELD_TO_CMS },
|
|
26
|
+
{name: TASKS_NAMES.REFERENCE_JOBS},
|
|
35
27
|
],
|
|
36
28
|
scheduleChildrenSequentially: true,
|
|
37
29
|
estimatedDurationSec: 30,
|
|
38
30
|
},
|
|
39
|
-
[TASKS_NAMES.
|
|
40
|
-
name: TASKS_NAMES.
|
|
31
|
+
[TASKS_NAMES.CREATE_COLLECTIONS]: {
|
|
32
|
+
name: TASKS_NAMES.CREATE_COLLECTIONS,
|
|
41
33
|
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
42
|
-
process:
|
|
34
|
+
process:createCollections,
|
|
43
35
|
shouldSkipCheck:()=>false,
|
|
44
|
-
estimatedDurationSec:
|
|
45
|
-
},
|
|
46
|
-
[TASKS_NAMES.CREATE_CITIES_COLLECTION]: {
|
|
47
|
-
name: TASKS_NAMES.CREATE_CITIES_COLLECTION,
|
|
48
|
-
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
49
|
-
process:()=>createCollectionIfMissing(COLLECTIONS.CITIES, COLLECTIONS_FIELDS.CITIES),
|
|
50
|
-
shouldSkipCheck:()=>false,
|
|
51
|
-
estimatedDurationSec:3
|
|
52
|
-
},
|
|
53
|
-
[TASKS_NAMES.CREATE_AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION]: {
|
|
54
|
-
name: TASKS_NAMES.CREATE_AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION,
|
|
55
|
-
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
56
|
-
process:()=>createCollectionIfMissing(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, COLLECTIONS_FIELDS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
|
|
57
|
-
shouldSkipCheck:()=>false,
|
|
58
|
-
estimatedDurationSec:3
|
|
36
|
+
estimatedDurationSec:7
|
|
59
37
|
},
|
|
60
38
|
[TASKS_NAMES.INSERT_JOBS_TO_CMS]: {
|
|
61
39
|
name: TASKS_NAMES.INSERT_JOBS_TO_CMS,
|
|
@@ -71,34 +49,20 @@ const TASKS = {
|
|
|
71
49
|
shouldSkipCheck:()=>false,
|
|
72
50
|
estimatedDurationSec:20
|
|
73
51
|
},
|
|
74
|
-
[TASKS_NAMES.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
[TASKS_NAMES.REFERENCE_JOBS_TO_LOCATIONS]: {
|
|
89
|
-
name: TASKS_NAMES.REFERENCE_JOBS_TO_LOCATIONS,
|
|
90
|
-
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
91
|
-
process:()=>referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.CITY, sourceCollection: COLLECTIONS.CITIES, jobField: JOBS_COLLECTION_FIELDS.CITY_TEXT }),
|
|
92
|
-
shouldSkipCheck:()=>false,
|
|
93
|
-
estimatedDurationSec:3
|
|
94
|
-
},
|
|
95
|
-
[TASKS_NAMES.REFERENCE_JOBS_TO_DEPARTMENT]: {
|
|
96
|
-
name: TASKS_NAMES.REFERENCE_JOBS_TO_DEPARTMENT,
|
|
97
|
-
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
98
|
-
process:()=>referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.DEPARTMENT_REF, sourceCollection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, jobField: JOBS_COLLECTION_FIELDS.DEPARTMENT }),
|
|
99
|
-
shouldSkipCheck:()=>false,
|
|
100
|
-
estimatedDurationSec:3
|
|
101
|
-
},
|
|
52
|
+
[TASKS_NAMES.AGGREGATE_JOBS_BY_FIELD_TO_CMS]: {
|
|
53
|
+
name: TASKS_NAMES.AGGREGATE_JOBS_BY_FIELD_TO_CMS,
|
|
54
|
+
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
55
|
+
process:aggregateJobs,
|
|
56
|
+
shouldSkipCheck:()=>false,
|
|
57
|
+
estimatedDurationSec:6
|
|
58
|
+
},
|
|
59
|
+
[TASKS_NAMES.REFERENCE_JOBS]: {
|
|
60
|
+
name: TASKS_NAMES.REFERENCE_JOBS,
|
|
61
|
+
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
|
62
|
+
process:referenceJobs,
|
|
63
|
+
shouldSkipCheck:()=>false,
|
|
64
|
+
estimatedDurationSec:6
|
|
65
|
+
},
|
|
102
66
|
[TASKS_NAMES.CREATE_API_KEY_COLLECTION_AND_FILL_IT]: {
|
|
103
67
|
name: TASKS_NAMES.CREATE_API_KEY_COLLECTION_AND_FILL_IT,
|
|
104
68
|
getIdentifier:()=> "SHOULD_NEVER_SKIP",
|
package/backend/data.js
CHANGED
|
@@ -18,7 +18,7 @@ function validatePosition(position) {
|
|
|
18
18
|
if (!position.department || !position.department.label) {
|
|
19
19
|
throw new Error('Position department is required and must have a label');
|
|
20
20
|
}
|
|
21
|
-
if (!position.location || !position.location.city ||
|
|
21
|
+
if (!position.location || !position.location.city || typeof position.location.remote !== 'boolean') {
|
|
22
22
|
throw new Error('Position location is required and must have a city and remote');
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -32,7 +32,7 @@ async function saveJobsDataToCMS() {
|
|
|
32
32
|
const basicJob = {
|
|
33
33
|
_id: position.id,
|
|
34
34
|
title: position.title,
|
|
35
|
-
department: position.department.label
|
|
35
|
+
department: position.department.label,
|
|
36
36
|
cityText: normalizeCityName(position.location.city),
|
|
37
37
|
location: position.location,
|
|
38
38
|
country: position.location.country,
|
|
@@ -130,6 +130,10 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
|
130
130
|
console.log(
|
|
131
131
|
` API chunk ${chunkNumber} completed: ${chunkSuccesses} success, ${chunkFailures} failed`
|
|
132
132
|
);
|
|
133
|
+
if (chunkNumber * API_CHUNK_SIZE < jobsWithNoDescriptions.items.length) {
|
|
134
|
+
console.log(' Waiting 2 seconds before next API chunk...');
|
|
135
|
+
await delay(2000);
|
|
136
|
+
}
|
|
133
137
|
},
|
|
134
138
|
});
|
|
135
139
|
|
|
@@ -154,7 +158,6 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
|
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
|
|
158
161
|
function iterateOverAllJobs(results, field) {
|
|
159
162
|
const jobsPerField = {};
|
|
160
163
|
const cityLocations = {};
|
|
@@ -296,8 +299,38 @@ async function createApiKeyCollectionAndFillIt() {
|
|
|
296
299
|
console.log("Smart token inserted into the ApiKey collection");
|
|
297
300
|
}
|
|
298
301
|
|
|
302
|
+
async function createCollections() {
|
|
303
|
+
console.log("Creating collections");
|
|
304
|
+
Promise.all(
|
|
305
|
+
[createCollectionIfMissing(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
|
|
306
|
+
createCollectionIfMissing(COLLECTIONS.CITIES, COLLECTIONS_FIELDS.CITIES),
|
|
307
|
+
createCollectionIfMissing(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, COLLECTIONS_FIELDS.AMOUNT_OF_JOBS_PER_DEPARTMENT)
|
|
308
|
+
]);
|
|
309
|
+
console.log("finished creating Collections");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async function aggregateJobs() {
|
|
313
|
+
console.log("Aggregating jobs");
|
|
314
|
+
Promise.all([
|
|
315
|
+
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.CITY_TEXT, collection: COLLECTIONS.CITIES }),
|
|
316
|
+
aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.DEPARTMENT, collection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT })
|
|
317
|
+
]);
|
|
318
|
+
console.log("finished aggregating jobs");
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function referenceJobs() {
|
|
322
|
+
console.log("Reference jobs");
|
|
323
|
+
Promise.all([
|
|
324
|
+
referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.CITY, sourceCollection: COLLECTIONS.CITIES, jobField: JOBS_COLLECTION_FIELDS.CITY_TEXT }),
|
|
325
|
+
referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.DEPARTMENT_REF, sourceCollection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, jobField: JOBS_COLLECTION_FIELDS.DEPARTMENT })
|
|
326
|
+
]);
|
|
327
|
+
console.log("finished referencing jobs");
|
|
328
|
+
}
|
|
299
329
|
|
|
300
330
|
module.exports = {
|
|
331
|
+
referenceJobs,
|
|
332
|
+
aggregateJobs,
|
|
333
|
+
createCollections,
|
|
301
334
|
saveJobsDataToCMS,
|
|
302
335
|
saveJobsDescriptionsAndLocationApplyUrlToCMS,
|
|
303
336
|
aggregateJobsByFieldToCMS,
|
|
@@ -3,7 +3,7 @@ const { items: wixData } = require('@wix/data');
|
|
|
3
3
|
const { COLLECTIONS } = require('./collectionConsts');
|
|
4
4
|
async function makeSmartRecruitersRequest(path,token) {
|
|
5
5
|
const baseUrl = 'https://api.smartrecruiters.com'; // PROD
|
|
6
|
-
//
|
|
6
|
+
//const baseUrl = 'https://bayank2.wixstudio.com/my-site-3//_functions'; // TEST
|
|
7
7
|
const fullUrl = `${baseUrl}${path}`;
|
|
8
8
|
|
|
9
9
|
//console.log(`Making request to: ${fullUrl}`);
|