-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkRequestDataSiloIdsCompleted.ts
More file actions
94 lines (85 loc) · 2.74 KB
/
markRequestDataSiloIdsCompleted.ts
File metadata and controls
94 lines (85 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { RequestDataSiloStatus } from '@transcend-io/privacy-types';
import { buildTranscendGraphQLClient, makeGraphQLRequest } from '@transcend-io/sdk';
import { map } from '@transcend-io/utils';
import colors from 'colors';
import { DEFAULT_TRANSCEND_API } from '../../constants.js';
import { logger } from '../../logger.js';
import { CHANGE_REQUEST_DATA_SILO_STATUS, fetchRequestDataSilo } from '../graphql/index.js';
import { withProgressBar } from '../helpers/index.js';
/**
* Given a CSV of Request IDs, mark associated RequestDataSilos as completed
*
* @param options - Options
* @returns Number of items marked as completed
*/
export async function markRequestDataSiloIdsCompleted({
requestIds,
dataSiloId,
auth,
concurrency = 100,
status = RequestDataSiloStatus.Resolved,
transcendUrl = DEFAULT_TRANSCEND_API,
}: {
/** The list of request ids to mark as completed */
requestIds: string[];
/** Transcend API key authentication */
auth: string;
/** Data Silo ID to pull down jobs for */
dataSiloId: string;
/** Status to update requests to */
status?: RequestDataSiloStatus;
/** Upload concurrency */
concurrency?: number;
/** API URL for Transcend backend */
transcendUrl?: string;
}): Promise<number> {
// Find all requests made before createdAt that are in a removing data state
const client = buildTranscendGraphQLClient(transcendUrl, auth);
// Time duration
const t0 = new Date().getTime();
// Notify Transcend
logger.info(
colors.magenta(
`Notifying Transcend for data silo "${dataSiloId}" marking "${requestIds.length}" requests as completed.`,
),
);
await withProgressBar(async (bar) => {
let total = 0;
bar.start(requestIds.length);
await map(
requestIds,
async (requestId) => {
const requestDataSilo = await fetchRequestDataSilo(client, {
requestId,
dataSiloId,
});
try {
await makeGraphQLRequest<{
/** Whether we successfully uploaded the results */
success: boolean;
}>(client, CHANGE_REQUEST_DATA_SILO_STATUS, {
variables: {
requestDataSiloId: requestDataSilo.id,
status,
},
logger,
});
} catch (err) {
if (
!err.message.includes('Client error: Request must be active:') &&
!err.message.includes('Failed to find RequestDataSilo')
) {
throw err;
}
}
total += 1;
bar.update(total);
},
{ concurrency },
);
});
const t1 = new Date().getTime();
const totalTime = t1 - t0;
logger.info(colors.green(`Successfully notified Transcend in "${totalTime / 1000}" seconds!`));
return requestIds.length;
}