-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (55 loc) · 1.68 KB
/
main.py
File metadata and controls
68 lines (55 loc) · 1.68 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
import asyncio
import os
from nexus_client_sdk.nexus.core.app_core import Nexus
from nexus_client_sdk.nexus.input.command_line import NexusDefaultArguments
from nexus_hello.hello_algorithm import HelloAlgorithm
from nexus_hello.models.payload import HelloData
def logger_tags_from_payload(
payload: HelloData, _: NexusDefaultArguments
) -> dict[str, str]:
"""
Extracts tags from payload used for logger
"""
return {
"author": payload.hello_author,
}
def metric_tags_from_payload(
payload: HelloData, run_args: NexusDefaultArguments
) -> dict[str, str]:
"""
Extracts tags from payload used for metrics
"""
return {
"author": payload.hello_author,
"request_id": run_args.request_id,
"algorithm_name": "nexus_hello",
}
def enrich_logger_from_payload(
_: HelloData, run_args: NexusDefaultArguments
) -> dict[str, dict[str, str]]:
"""
Extracts tags from payload used for logging
"""
return {
"(request_id:{request_id})": {"request_id": run_args.request_id},
}
async def main():
"""
Main function to run the Nexus Hello Algorithm
"""
nexus = Nexus.create()
nexus._run_args.sas_uri = nexus._run_args.sas_uri.replace(
"http://localhost:9000",
os.getenv("PROTEUS__AWS_ENDPOINT", "http://localhost:9000"),
)
nexus = (
nexus.use_algorithm(HelloAlgorithm)
.inject_payload(HelloData)
.with_log_enricher(
tagger=logger_tags_from_payload, enricher=enrich_logger_from_payload
)
.with_metric_tagger(tagger=metric_tags_from_payload)
)
await nexus.activate()
if __name__ == "__main__":
asyncio.run(main())