-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublisher.py
51 lines (42 loc) · 1.06 KB
/
publisher.py
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
import json
import uuid
import click
import redis
@click.command("publish")
@click.argument("file")
@click.option(
"--url",
help="URL of the redis server.",
default="redis://127.0.0.1:6389",
show_default=True,
)
def publish(file, url):
with open(file, "r") as f:
protocol = json.loads(f.read())
metadata = {
"spec": {
"experimentId": "123",
"runId": "abc",
}
}
if isinstance(protocol["spec"], list):
metadata["spec"] = [
{
"experimentId": "123",
"runId": "abc",
}
]
data = {
**protocol,
**{
"uuid": uuid.uuid4().hex[:16],
"metadata": {
"source": "test",
**metadata,
},
},
}
publisher = redis.StrictRedis.from_url(url)
publisher.publish(data["apiVersion"], json.dumps(data))
if __name__ == "__main__":
publish()