sr-npm 1.7.118 → 1.7.119

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/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
- FILL_JOBS_PER_CITY_COLLECTION: 'fillJobsPerCityCollection',
12
- FILL_JOBS_PER_DEPARTMENT_COLLECTION: 'fillJobsPerDepartmentCollection',
13
- REFERENCE_JOBS_TO_LOCATIONS: 'referenceJobsToLocations',
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.CREATE_JOBS_COLLECTION },
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.FILL_JOBS_PER_CITY_COLLECTION },
32
- { name: TASKS_NAMES.FILL_JOBS_PER_DEPARTMENT_COLLECTION },
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
- estimatedDurationSec: 30,
29
+ estimatedDurationSec: 60,
38
30
  },
39
- [TASKS_NAMES.CREATE_JOBS_COLLECTION]: {
40
- name: TASKS_NAMES.CREATE_JOBS_COLLECTION,
31
+ [TASKS_NAMES.CREATE_COLLECTIONS]: {
32
+ name: TASKS_NAMES.CREATE_COLLECTIONS,
41
33
  getIdentifier:()=> "SHOULD_NEVER_SKIP",
42
- process:()=>createCollectionIfMissing(COLLECTIONS.JOBS, COLLECTIONS_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
34
+ process:createCollections,
43
35
  shouldSkipCheck:()=>false,
44
- estimatedDurationSec:3
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.FILL_JOBS_PER_CITY_COLLECTION]: {
75
- name: TASKS_NAMES.FILL_JOBS_PER_CITY_COLLECTION,
76
- getIdentifier:()=> "SHOULD_NEVER_SKIP",
77
- process:()=>aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.CITY_TEXT, collection: COLLECTIONS.CITIES }),
78
- shouldSkipCheck:()=>false,
79
- estimatedDurationSec:3
80
- },
81
- [TASKS_NAMES.FILL_JOBS_PER_DEPARTMENT_COLLECTION]: {
82
- name: TASKS_NAMES.FILL_JOBS_PER_DEPARTMENT_COLLECTION,
83
- getIdentifier:()=> "SHOULD_NEVER_SKIP",
84
- process:()=>aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.DEPARTMENT, collection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT }),
85
- shouldSkipCheck:()=>false,
86
- estimatedDurationSec:3
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 || typeof position.location.remote !== 'boolean') {
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
 
@@ -34,7 +34,7 @@ async function saveJobsDataToCMS() {
34
34
  const basicJob = {
35
35
  _id: position.id,
36
36
  title: position.title,
37
- department: position.department.label.replace('&', ' and '),
37
+ department: position.department.label,
38
38
  cityText: normalizeCityName(position.location.city),
39
39
  location: position.location,
40
40
  country: position.location.country,
@@ -43,6 +43,7 @@ async function saveJobsDataToCMS() {
43
43
  postingStatus: position.postingStatus,
44
44
  jobDescription: null, // Will be filled later
45
45
  };
46
+ console.log("basicJob", basicJob);
46
47
  return basicJob;
47
48
  });
48
49
  console.log("jobsData@@@@@@@", jobsData);
@@ -133,6 +134,10 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
133
134
  console.log(
134
135
  ` API chunk ${chunkNumber} completed: ${chunkSuccesses} success, ${chunkFailures} failed`
135
136
  );
137
+ if (chunkNumber * API_CHUNK_SIZE < jobsWithNoDescriptions.items.length) {
138
+ console.log(' Waiting 2 seconds before next API chunk...');
139
+ await delay(2000);
140
+ }
136
141
  },
137
142
  });
138
143
 
@@ -157,7 +162,6 @@ async function saveJobsDescriptionsAndLocationApplyUrlToCMS() {
157
162
  }
158
163
  }
159
164
 
160
-
161
165
  function iterateOverAllJobs(results, field) {
162
166
  const jobsPerField = {};
163
167
  const cityLocations = {};
@@ -299,8 +303,36 @@ async function createApiKeyCollectionAndFillIt() {
299
303
  console.log("Smart token inserted into the ApiKey collection");
300
304
  }
301
305
 
306
+ async function createCollections() {
307
+ console.log("Creating collections");
308
+ Promise.all(
309
+ [createCollectionIfMissing(COLLECTIONS.JOBS, JOBS_COLLECTION_FIELDS.JOBS,{ insert: 'ADMIN', update: 'ADMIN', remove: 'ADMIN', read: 'ANYONE' }),
310
+ createCollectionIfMissing(COLLECTIONS.CITIES, COLLECTIONS_FIELDS.CITIES),
311
+ createCollectionIfMissing(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, COLLECTIONS_FIELDS.AMOUNT_OF_JOBS_PER_DEPARTMENT)
312
+ ]);
313
+ console.log("finished creating Collections");
314
+ }
315
+
316
+ async function aggregateJobs() {
317
+ console.log("Aggregating jobs");
318
+ Promise.all([
319
+ aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.CITY_TEXT, collection: COLLECTIONS.CITIES }),
320
+ aggregateJobsByFieldToCMS({ field: JOBS_COLLECTION_FIELDS.DEPARTMENT, collection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT })
321
+ ]);
322
+ console.log("finished aggregating jobs");
323
+ }
324
+
325
+ async function referenceJobs() {
326
+ console.log("Reference jobs");
327
+ await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.DEPARTMENT_REF, sourceCollection: COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT, jobField: JOBS_COLLECTION_FIELDS.DEPARTMENT })
328
+ await referenceJobsToField({ referenceField: JOBS_COLLECTION_FIELDS.CITY, sourceCollection: COLLECTIONS.CITIES, jobField: JOBS_COLLECTION_FIELDS.CITY_TEXT }),
329
+ console.log("finished referencing jobs");
330
+ }
302
331
 
303
332
  module.exports = {
333
+ referenceJobs,
334
+ aggregateJobs,
335
+ createCollections,
304
336
  saveJobsDataToCMS,
305
337
  saveJobsDescriptionsAndLocationApplyUrlToCMS,
306
338
  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
- // const baseUrl = 'https://bayank2.wixstudio.com/my-site-3//_functions'; // TEST
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}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.118",
3
+ "version": "1.7.119",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {