Skip to content

Commit

Permalink
Makes compare() method connect to backend RPC server with each request (
Browse files Browse the repository at this point in the history
#366)

### Related issues

- Closes #364 

### Summary

- changes the behavior of the OakRPCMarshaller's compare() method to
first establish a connection to Oak, then perform the request.
previously the connection was made once when the API booted

### Checks

- [ ] All tests have passed (or issues created for failing tests)
  • Loading branch information
falquaddoomi authored Oct 3, 2023
1 parent bd8385e commit 4467911
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backend/src/monarch_py/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ def solr():

class OakRPCMarshaller:
def __init__(self) -> None:
pass

def connect_to_oak(self):
ctx = zmq.Context()
rpc_client = RPCClient(
JSONRPCProtocol(),
ZmqClientTransport.create(
ctx, f'tcp://{settings.oak_server_host}:{settings.oak_server_port}'
)
)
self.oak_server = rpc_client.get_proxy()
return rpc_client.get_proxy()

def compare(self, *args, **kwargs):
# make the connection each time to the backend server, to get around it timing out
# (note to future readers: if we find this to be too expensive, we can
# try the existing connection and reconnect if there's an exception)
self.oak_server = self.connect_to_oak()

# for some reason TermSetPairwiseSimilarity is not JSON-serializable so
# we can't call compare() directly. instead, we call compare_as_dict(),
# which sends back a dict, and then we convert it into the expected
Expand Down

0 comments on commit 4467911

Please sign in to comment.