-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcalls.ts
57 lines (44 loc) · 1.67 KB
/
calls.ts
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
import { parseNewMonth, parseNOldMonths, parseOldMonth } from '@/modules/parser/parse';
import { getAppNow } from '@/libs/datetime';
import { SERVER_CONFIG } from '@/config/server';
import { ParserResponse } from '@/types/api';
import { ParserResult } from '@/types/parser';
const { oldMonthsCount } = SERVER_CONFIG;
/**
* Reused in:
*
* modules/scheduler/main.ts
* app/api/parser/[script]/route.ts
* modules/parser/main.ts
*
* ! invalidate all database keys here, for scheduler, api, cli // WRONG
*
* These can throw.
*/
export const callParseNewMonth = async (): Promise<ParserResponse> => {
const parserResult: ParserResult = await parseNewMonth();
// ! here this WONT work, because this function is called in another process, scheduler, cli
// ! must detect database change or message queue
// await getCacheDatabase().clear();
const parserResponse: ParserResponse = {
parseMessage: `Parsing new month successful, now: ${getAppNow()}.`,
parserResults: [parserResult],
};
return parserResponse;
};
export const callParseOldMonth = async (): Promise<ParserResponse> => {
const parserResult: ParserResult = await parseOldMonth();
const parserResponse: ParserResponse = {
parseMessage: `Parsing old month successful, now: ${getAppNow()}.`,
parserResults: [parserResult],
};
return parserResponse;
};
export const callParseNOldMonths = async (): Promise<ParserResponse> => {
const parserResults: ParserResult[] = await parseNOldMonths(oldMonthsCount);
const parserResponse: ParserResponse = {
parserResults,
parseMessage: `Parsing ${parserResults.length} old months successful, now: ${getAppNow()}.`,
};
return parserResponse;
};