abmp-npm 2.0.17 → 2.0.18
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.
|
@@ -9,9 +9,10 @@ const { bulkProcessAndSaveMemberData } = require('./bulk-process-methods');
|
|
|
9
9
|
const { SITES_WITH_INTERESTS_TO_MIGRATE } = require('./consts');
|
|
10
10
|
const { isUpdatedMember, isSiteAssociatedMember } = require('./utils');
|
|
11
11
|
|
|
12
|
-
async function syncMembersDataPerAction(
|
|
12
|
+
async function syncMembersDataPerAction(taskData) {
|
|
13
|
+
const { action, backupDate } = taskData;
|
|
13
14
|
try {
|
|
14
|
-
const firstPageResponse = await fetchPACMembers(1, action);
|
|
15
|
+
const firstPageResponse = await fetchPACMembers({ page: 1, action, backupDate });
|
|
15
16
|
|
|
16
17
|
if (
|
|
17
18
|
!firstPageResponse ||
|
|
@@ -48,6 +49,7 @@ async function syncMembersDataPerAction(action) {
|
|
|
48
49
|
data: {
|
|
49
50
|
pageNumber,
|
|
50
51
|
action,
|
|
52
|
+
...(backupDate ? { backupDate } : {}),
|
|
51
53
|
},
|
|
52
54
|
type: 'scheduled',
|
|
53
55
|
}));
|
|
@@ -74,11 +76,11 @@ async function syncMembersDataPerAction(action) {
|
|
|
74
76
|
* @returns {Promise<Object>} - Page synchronization result
|
|
75
77
|
*/
|
|
76
78
|
async function synchronizeSinglePage(taskObject) {
|
|
77
|
-
const { pageNumber, action } = taskObject.data;
|
|
79
|
+
const { pageNumber, action, backupDate } = taskObject.data;
|
|
78
80
|
try {
|
|
79
81
|
const [siteAssociation, memberDataResponse] = await Promise.all([
|
|
80
82
|
getSiteConfigs(CONFIG_KEYS.SITE_ASSOCIATION),
|
|
81
|
-
fetchPACMembers(pageNumber, action),
|
|
83
|
+
fetchPACMembers({ page: pageNumber, action, backupDate }),
|
|
82
84
|
]);
|
|
83
85
|
const addInterests = SITES_WITH_INTERESTS_TO_MIGRATE.includes(siteAssociation);
|
|
84
86
|
if (
|
package/backend/jobs.js
CHANGED
|
@@ -13,12 +13,18 @@ async function runScheduledTasks() {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Schedule a daily pull task for the given backup date
|
|
18
|
+
* @param {string} backupDate - Optional. The date of the backup to pull in format YYYY-MM-DD
|
|
19
|
+
* @returns {Promise<void>}
|
|
20
|
+
*/
|
|
21
|
+
async function scheduleDailyPullTask(backupDate = null) {
|
|
17
22
|
try {
|
|
18
23
|
console.log('scheduleDailyPullTask started!');
|
|
24
|
+
console.log(`backupDate: ${backupDate}`);
|
|
19
25
|
return await taskManager().schedule({
|
|
20
26
|
name: TASKS_NAMES.ScheduleDailyMembersDataSync,
|
|
21
|
-
data: {},
|
|
27
|
+
data: backupDate ? { backupDate } : {}, // keeping it like this so it would be easier to understand which task was backed up which is not while looking into CMS.
|
|
22
28
|
type: 'scheduled',
|
|
23
29
|
});
|
|
24
30
|
} catch (error) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { PAC_API_URL } = require('./consts');
|
|
1
|
+
const { PAC_API_URL, BACKUP_API_URL } = require('./consts');
|
|
2
2
|
const { getSecret } = require('./utils');
|
|
3
3
|
|
|
4
4
|
const getHeaders = async () => {
|
|
@@ -8,8 +8,22 @@ const getHeaders = async () => {
|
|
|
8
8
|
};
|
|
9
9
|
return headers;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {*} params
|
|
14
|
+
* @param {number} params.page - The page number to fetch
|
|
15
|
+
* @param {string} params.action - The action to fetch
|
|
16
|
+
* @param {string} [params.backupDate] - Optional. The backup date to fetch in format YYYY-MM-DD, use only to fetch from backup endpoint not from PAC endpoint.
|
|
17
|
+
* @returns {Promise<Object>} - The response from the API
|
|
18
|
+
*/
|
|
19
|
+
const fetchPACMembers = async ({ page, action, backupDate }) => {
|
|
20
|
+
const baseUrl = backupDate ? BACKUP_API_URL : PAC_API_URL;
|
|
21
|
+
const queryParams = { page, actionFilter: action };
|
|
22
|
+
if (backupDate) {
|
|
23
|
+
queryParams.date = backupDate;
|
|
24
|
+
}
|
|
25
|
+
const url = `${baseUrl}/Members?${new URLSearchParams(queryParams).toString()}`;
|
|
26
|
+
console.log(`Fetching PAC members from: ${url}`);
|
|
13
27
|
const headers = await getHeaders();
|
|
14
28
|
const fetchOptions = {
|
|
15
29
|
method: 'get',
|
|
@@ -18,14 +32,14 @@ const fetchPACMembers = async (pageNum, actionFilter) => {
|
|
|
18
32
|
const response = await fetch(url, fetchOptions);
|
|
19
33
|
const responseType = response.headers.get('content-type');
|
|
20
34
|
if (!responseType.includes('application/json')) {
|
|
21
|
-
const errorMessage = `[fetchPACMembers] got invalid responseType: ${responseType} for page ${
|
|
35
|
+
const errorMessage = `[fetchPACMembers] got invalid responseType: ${responseType} for page ${page} and actionFilter ${action}`;
|
|
22
36
|
console.error(errorMessage);
|
|
23
37
|
throw new Error(errorMessage);
|
|
24
38
|
}
|
|
25
39
|
if (response.ok) {
|
|
26
40
|
return response.json();
|
|
27
41
|
} else {
|
|
28
|
-
const errorMessage = `[fetchPACMembers] failed with status ${response.status} for page ${
|
|
42
|
+
const errorMessage = `[fetchPACMembers] failed with status ${response.status} for page ${page} and actionFilter ${action}`;
|
|
29
43
|
console.error(errorMessage);
|
|
30
44
|
throw new Error(errorMessage);
|
|
31
45
|
}
|
|
@@ -43,7 +43,7 @@ const TASKS = {
|
|
|
43
43
|
},
|
|
44
44
|
[TASKS_NAMES.ScheduleMembersDataPerAction]: {
|
|
45
45
|
name: TASKS_NAMES.ScheduleMembersDataPerAction,
|
|
46
|
-
getIdentifier: task => task.data
|
|
46
|
+
getIdentifier: task => task.data,
|
|
47
47
|
process: syncMembersDataPerAction,
|
|
48
48
|
shouldSkipCheck: () => false,
|
|
49
49
|
estimatedDurationSec: 6,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abmp-npm",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.18",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"check-cycles": "madge --circular .",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"csv-parser": "^3.0.0",
|
|
51
51
|
"ngeohash": "^0.6.3",
|
|
52
52
|
"phone": "^3.1.67",
|
|
53
|
-
"psdev-task-manager": "1.1.
|
|
53
|
+
"psdev-task-manager": "1.1.10",
|
|
54
54
|
"psdev-utils": "1.1.1"
|
|
55
55
|
}
|
|
56
56
|
}
|