forked from bluesky/bluesky-pods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadaptive_consumer.py
53 lines (37 loc) · 1.22 KB
/
adaptive_consumer.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
52
53
import json
import redis
from bluesky_adaptive import recommendations
from bluesky_adaptive import per_start
import msgpack
import msgpack_numpy as mpn
from functools import partial
from bluesky_kafka import RemoteDispatcher
d = RemoteDispatcher(
topics=["adaptive"],
bootstrap_servers="127.0.0.1:9092",
group_id="kafka-unit-test-group-id",
# "latest" should always work but
# has been failing on Linux, passing on OSX
consumer_config={"auto.offset.reset": "latest"},
polling_duration=1.0,
deserializer=partial(msgpack.loads, object_hook=mpn.decode),
)
class RedisQueue:
"fake just enough of the queue.Queue API on top of redis"
def __init__(self, client):
self.client = client
def put(self, value):
print(f"pushing {value}")
self.client.lpush("adaptive", json.dumps(value))
rq = RedisQueue(redis.StrictRedis(host="localhost", port=6379, db=0))
adaptive_obj = recommendations.StepRecommender(1.5)
independent_keys = ["motor"]
dependent_keys = ["det"]
queue = rq
max_count = 15
rr, _ = per_start.recommender_factory(
adaptive_obj, independent_keys, dependent_keys, max_count=max_count, queue=queue
)
d.subscribe(rr)
print("REMOTE IS READY TO START")
d.start()