anomaly / gallagher

The missing toolkit for extending Gallagher Command Centre, featuring a CLI, SQL interface, TUI and a Python idiomatic SDK
https://anomaly.github.io/gallagher/
MIT License
11 stars 2 forks source link

Outline a callback pattern for implementing long poll methods #19

Open devraj opened 9 months ago

devraj commented 9 months ago

Various entities provide a long poll mechanism to get changes as they occur on the server (I assume this is due to the lack of webhooks, which would be difficult to proxy in the current environment, and for clients like what we are building long poll would make sense in certain use cases).

The endpoints generally seem to return a response if there are any, otherwise return a 400 and hang up.

This ticket is to study these endpoints like cardholder, alarms, etc and determine a pattern so all of them can follow the same design principles.

devraj commented 8 months ago

See #18 comment on streaming message now that we have moved to asyncio

devraj commented 4 months ago

Given we are using async functions, we should just stick with using yield to return objects as we receive them from the long poll endpoints.

devraj commented 4 months ago

While building the shillelagh adapter see #31, I saw it uses the following pattern for returning rows of data. shillelagh has the same pattern of querying an API and returning a SQL resulset.

It's worth noting the Iterator[Row] + yield patter to return incremental results:

    def get_data(  # pylint: disable=too-many-locals
        self,
        bounds: Dict[str, Filter],
        order: List[Tuple[str, RequestedOrder]],
        **kwargs: Any,
    ) -> Iterator[Row]:
        yield {
            "rowid": 1,
            "id": 1,
            "authorised": True,
            "first_name": "Dev",
            "last_name": "Mukherjee",
        }