forked from aws/firelens-datajet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
61 lines (51 loc) · 1.86 KB
/
app.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
58
59
60
61
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import generatorTemplates from "./generators/generator-index.js"
import datajetTemplates from "./datajets/datajet-index.js"
import { buildStage, deepFreezePipeline, executePipeline } from "./core/pipeline.js";
import { IExecutePipelineConfig } from "./core/pipeline-types.js";
import dotenv from 'dotenv';
import { IClient } from "./core/ext-types.js";
import clientsIndex from "./clients/client-index.js";
import { buildPipeline, IPipelineSchema } from "./core/rockefeller.js";
/*
* App environment variables
* CLIENTS=["<client1>", "<client2>", ...]
* | default_value: ["request"]
* | options: "request", "file", "environment"
*/
/* Load environment variables */
dotenv.config();
let clients: Array<string>;
try {
clients = JSON.parse(process.env.CLIENTS ?? "[\"file\"]");
}
catch (e) {
console.log("Unable to parse clients JSON environment variable");
}
const processClient = async (client: IClient) => {
const commandGenerator = client.makeCommandGenerator();
for await (const command of commandGenerator) {
if (command == null) {
continue;
}
const executionResult = await processPipeline(command.pipelineConfiguration);
command.handleExecutionResult(executionResult);
}
}
/* Spin up all clients */
clients.forEach(clientName => {
const client = clientsIndex
.find((clientTemplate => clientTemplate.name === clientName));
processClient(client);
})
async function processPipeline(config: any) {
const pipeline = buildPipeline(config as IPipelineSchema);
const pipelineConfig: IExecutePipelineConfig = {
onExecutionFailure: async () => {console.log("Execution failed");}
};
deepFreezePipeline(pipeline);
return await executePipeline(pipeline, pipelineConfig);
}