ChristianTremblay / pyhaystack

Pyhaystack is a module that allow python programs to connect to a haystack server project-haystack.org. Connection can be established with Niagara Platform running the nhaystack, Skyspark and Widesky. For this to work with Anaconda IPython Notebook in Windows, be sure to use "python setup.py install" using the Anaconda Command Prompt in Windows. If not, module will be installed for System path python but won't work in the environment of Anaconda IPython Notebook. You will need hszinc 1.3+ for this to work.
Apache License 2.0
74 stars 32 forks source link

isConnected variable doesn't keep track of connectivity to server #1

Closed ChristianTremblay closed 8 years ago

ChristianTremblay commented 8 years ago

If session has been defined for too long, it will be closed by server. A call of session.something will fail. Maybe we should reconnect more often, or deal with that differently...

sjlongland commented 8 years ago

In the past, I've usually taken the current timestamp (from time.time()), added some expiry time to it, and stored that.

isConnected then simply becomes a property:

@property
def isConnected(self):
    return self._auth_expiry > time.time()

If the implementation provides an expiry (e.g. Widesky does), then we just use that expiry time. Otherwise, we can add some nominal expiry time (user configurable) to the current time.

From what I gather with Niagara AX, it uses HTTP basic authentication, so doesn't establish a true "session", the credentials are provided on every request. HTTP digest authentication would be the same.

ChristianTremblay commented 8 years ago

The async engine will handle that