Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
74 lines (67 loc) · 1.74 KB
/
Copy pathindex.ts
File metadata and controls
74 lines (67 loc) · 1.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
import { Command } from 'commander';
import _ from 'lodash';
import { STAGE } from './types';
import enqueueStages from './stages';
import * as allStagesJob from './cronjobs/allStagesJob';
import initServer from './server';
import Logger from './utils/logger';
const logger = Logger('ETL');
/*
* ##### Define CLI arguments using Commander
*/
const program = new Command();
program
.option('--extract', 'include EXTRACT stage')
.option('--transform', 'include TRANSFORM stage')
.option('--load', 'include LOAD stage')
.option('--all', 'run all stages')
.option(
'--cron',
'run application as recurring cron job that will run all stages on schedule defined in env variables',
)
.option(
'--server',
'run express server to interact with cron job via web API - includes health check needed for Kubernetes liveness probe',
)
.parse();
/*
* ##### Transform provided arguments into the stages to run
*/
const options = program.opts();
const stages: Set<STAGE> = new Set<STAGE>();
if (options.all) {
stages.add(STAGE.EXTRACT);
stages.add(STAGE.TRANSFORM);
stages.add(STAGE.LOAD);
}
if (options.extract) {
stages.add(STAGE.EXTRACT);
}
if (options.transform) {
stages.add(STAGE.TRANSFORM);
}
if (options.load) {
stages.add(STAGE.LOAD);
}
/*
* ##### Send selected stages to the main program
*/
if (stages.size > 0) {
// If any stages were requested, lets run the main program
enqueueStages(Array.from(stages));
} else if (!options.cron && !options.server) {
// Otherwise shut it down
logger.error('No stages or instructions provided. Nothing will run.');
}
/*
* ##### When run with cron job flag
*/
if (options.cron) {
allStagesJob.init();
}
/*
* ##### When run with server flag
*/
if (options.server) {
initServer();
}