-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.ts
69 lines (66 loc) · 1.75 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
62
63
64
65
66
67
68
69
import { CronJob } from "cron";
import {
CRON_PATTERN,
LDES_DEREFERENCE_MEMBERS,
LDES_ENDPOINT_HEADER_PREFIX,
LDES_ENDPOINT_VIEW,
LDES_POLLING_INTERVAL,
LDES_REQUESTS_PER_MINUTE,
LDES_STREAM,
LDES_TIMESTAMP_PATH,
LDES_VERSION_OF_PATH,
REPLACE_VERSIONS,
RUNONCE
} from "./config";
import { ConfigurableLDESOptions } from "./consumer";
import LdesPipeline from "./ldes-pipeline";
import { NamedNode } from "n3";
let taskIsRunning = false;
const consumerJob = new CronJob(CRON_PATTERN, async () => {
if (taskIsRunning) {
console.log("Another task is still running");
return;
}
try {
taskIsRunning = true;
const endpoint = LDES_ENDPOINT_VIEW;
if (endpoint) {
const ldesOptions: ConfigurableLDESOptions = {
dereferenceMembers: LDES_DEREFERENCE_MEMBERS,
pollingInterval: LDES_POLLING_INTERVAL
};
if (LDES_REQUESTS_PER_MINUTE) {
ldesOptions.requestsPerMinute = LDES_REQUESTS_PER_MINUTE;
}
const datasetIri = new NamedNode(LDES_STREAM);
const consumer = new LdesPipeline({ datasetIri, endpoint, ldesOptions });
console.log("Started processing " + endpoint);
await consumer.consumeStream();
console.log("Finished processing " + endpoint);
if (RUNONCE) {
console.log("Job is complete.");
process.exit();
}
} else {
throw new Error("No endpoint provided");
}
} catch (e) {
console.error(e);
} finally {
taskIsRunning = false;
}
});
console.log("config", {
CRON_PATTERN,
LDES_DEREFERENCE_MEMBERS,
LDES_ENDPOINT_HEADER_PREFIX,
LDES_ENDPOINT_VIEW,
LDES_POLLING_INTERVAL,
LDES_REQUESTS_PER_MINUTE,
LDES_STREAM,
LDES_TIMESTAMP_PATH,
LDES_VERSION_OF_PATH,
REPLACE_VERSIONS,
RUNONCE
});
consumerJob.start();