Repository navigation
Expand file tree
/
Copy pathhandler_ingest.yaml
More file actions
154 lines (131 loc) · 6.53 KB
/
Copy pathhandler_ingest.yaml
File metadata and controls
154 lines (131 loc) · 6.53 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Language: Benthos YAML, Project: DatAasee, License: MIT, Author: Christian Himpe
processor_resources:
- label: 'handler_ingest'
processors:
- label: 'handler_ingest__cache_lock'
branch:
processors:
- cache:
resource: 'global_cache'
operator: 'exists'
key: 'ingesting'
result_map: 'meta ingesting = this'
- switch:
- check: 'content().string().trim() == "" || this.catch(null) == {}'
processors:
- mapping: |
meta status = "200"
root.data.type = "system"
root.data.id = timestamp_unix().string()
root.data.attributes.started = metadata("ingesting").bool()
- check: 'metadata("ingesting")'
processors:
- mapping: |
meta status = "503"
root.errors = [{"title": "Server error: Service Unavailable",
"detail": "Already ingesting."}]
- processors:
- try:
- label: 'handler_ingest__filter_body'
mapping: |
let body = this.catch(content().parse_form_url_encoded())
root = $body.with("username","password")
root.source = $body.source.or("").trim()
root.options = $body.options.or("").trim().trim("&")
root.method = $body.method.or("").trim().lowercase()
root.format = $body.format.or("").trim().lowercase()
root.steward = $body.steward.or("").trim()
root.rights = $body.rights.or("").trim()
- label: 'handler_ingest__validate_body'
json_schema:
schema_path: 'file:///schemas/request/ingest.json'
- label: 'handler_ingest__preserve_body'
mapping: |
meta ingest = this
- label: 'handler_ingest__set_lock'
cache:
resource: 'global_cache'
operator: 'set'
key: 'ingesting'
- mapping: |
meta status = "202"
root.data.type = "system"
root.data.id = timestamp_unix().string()
root.data.attributes.started = true
- catch:
- mapping: |
meta status = "400"
root.errors = [{"title": "Request Error: Bad Request",
"detail": "Request failed to pass schema validation.",
"links": {"about": "${DL_BASE}${DL_PATH}/api?request=ingest"}}]
- label: 'handler_ingest_async'
processors:
- switch:
- check: 'metadata("ingest") != null'
processors:
- log:
message: 'Ingest started from ${! metadata("ingest").source } via ${! metadata("ingest").method } as ${! metadata("ingest").format }.'
- mapping: |
meta timer_start = timestamp_unix()
meta count = 0
meta failed = 0
- label: 'handler_ingest_async__arcadedb_insert_source'
arcadedb:
host: '${DB_HOST}'
port: ${DB_PORT} # yamllint disable-line rule:quoted-strings
endpoint: 'command'
database: '${DB_NAME}'
username: '${DB_USER}'
password: '${DB_PASS}'
request: |
root.language = "sqlscript"
root.params.core = metadata("ingest").source + " " + metadata("ingest").method + " " + metadata("ingest").format + "%"
root.params.name = metadata("ingest").source + " " + metadata("ingest").method + " " + metadata("ingest").format + " (" + metadata("timer_start").ts_format("2006-01-02 15:04:05") + ")"
root.params.data = metadata("ingest").source
root.command = """DELETE FROM Sources WHERE name ILIKE :core;
INSERT INTO Sources SET name = :name, data = :data;"""
response: |
meta source_rid = this.result.0."@rid"
- resource: 'methods'
- try:
- log:
message: 'Ingest completed from ${! metadata("ingest").source } of ${! metadata("count").string() } records (of which ${! metadata("failed").string() } failed) after ${! "%.1f".format((timestamp_unix() - metadata("timer_start")) / 3600.0) }h.'
- label: 'handler_ingest__arcadedb_refresh_facets'
arcadedb:
host: '${DB_HOST}'
port: ${DB_PORT} # yamllint disable-line rule:quoted-strings
endpoint: 'command'
database: '${DB_NAME}'
username: '${DB_USER}'
password: '${DB_PASS}'
retries: 0
request: |
root.language = "sql"
root.awaitResponse = false
root.command = "REFRESH MATERIALIZED VIEW Facets;"
- log:
message: 'Facet refresh started.'
- resource: 'interconnect'
- log:
message: 'Interconnect started asynchronously in database. See database log for details.'
- catch:
- log:
message: 'Ingest incomplete: ${! metadata("ingest").source } failed due to: ${! error() }'
- label: 'handler_ingest_async__arcadedb_cleanup'
arcadedb:
host: '${DB_HOST}'
port: ${DB_PORT} # yamllint disable-line rule:quoted-strings
endpoint: 'command'
database: '${DB_NAME}'
username: '${DB_USER}'
password: '${DB_PASS}'
request: |
root.language = "sql"
root.command = "SET GLOBAL $interlock = null;"
- mapping: |
meta ingest = deleted()
- label: 'async_ingest__clear_lock_after_finish'
cache:
resource: 'global_cache'
operator: 'delete'
key: 'ingesting'