I have two services which each of the has the ability to update the same Graph. (C#)
One of them is longer than the other. Sometimes they might try to run together.
My code for connecting is the same -
public void Connect()
{
if (!_client.IsConnected)
{
_client.ConnectAsync().Wait();
}
}
Issue is, when the longer service is working, it's connected, and the second one gets stuck on the wait, even when the long one finishes.
I assumed the 'wait' should do the trick. I thought about adding a validation before getting the lock, with some sort of sleep and a recursive call when graph is locked, but found no API for it.
What's the solution in this case? I'd appreciate some guidance. Thanks!
Are you trying to synchronize these two processes so they don't access the graph concurrently? If so, is this because they will update the same parts of the graph?
I am not a C# developer, but I assume the 'wait' method has a timeout option. You can retry getting a connection if it times out, or proceed with your processing if it does not.
It seems bug in the client code. Can you share more details about your client code? I don't understand your statement about locking graph? Do you want to make sure if client 1 is running client 2 should not be making updates to the graph?
If so, how are you checking the status of the other application to make sure this one can run or not?
If you want to leverage the database to synchronize the flows, then you can leverage the locking mechanism of database.
Have a single node in the graph and update that node property as the first step in the transaction in the both apps. This way database will serialize the updates. Again this is crudest form of synchronizing the applications.
Yes, I do want two clients to update the graph, I don't check the status since there's no method of it in the API - this was my issue I was looking to solve.
Your idea of the single node in the graph is very creative - I liked it! Might go with it. Thanks!
Yes, looks like adding a wait and try is the safest option, I hoped for something like it from the neo API (preferably just a 'isLocked' instead). Thanks