Search code examples
circuit-sdk

Q: client.logon in Google Function expires


We are trying to deploy a bot in a google function as the example of Trivia but using the Client object. It works, but the next day the bot appears as disconnected.

How long is a circuit session? Is it possible to create the client within a google function?

It is not a token problem, every time a new one is generated we store it in Datastore and collect it from there.


Solution

  • Google Cloud Functions are stateless, they get unloaded unless you have steady load, at which time the SDKs websocket connection closed, hence the bot is offline.

    The Circuit SDK is not the best API to use in Cloud Functions, the REST API (as used in the trivia example) would work much better. The SDK is great for a browser app, or a NodeJS app that stays alive.

    Now in terms of the Circuit SDK, you are correct, even though the token is still valid, the session will time out after one minute. Of course this is only the case if the app stops (i.e. websocket is closed).

    More info on the GCF's execution environment can be found here.