Skip to content

Implement pagination support for local evaluation #204

@khvn26

Description

@khvn26

When updating the environment document asynchronously, exhaust all pages.

The following python code describes the process of consuming all api/v1/environment-document pages, the compiled_document should be stored as the environment document in the SDKs local memory cache.

import json

import requests

ENVIRONMENT_KEY = "<server key>"
BASE_API_URL = "https://edge.api.flagsmith.com"

session = requests.Session()
session.headers.update({"X-Environment-Key": ENVIRONMENT_KEY})


if __name__ == "__main__":
    documents = []
    url = f"{BASE_API_URL}/api/v1/environment-document"

    while True:
        env_doc_response = session.get(url)
        documents.append(env_doc_response.json())

        if not env_doc_response.links:
            break

        url = f'{BASE_API_URL}{env_doc_response.links["next"]["url"]}'

    compiled_document = documents[0]
    for document in documents[1:]:
        compiled_document["identity_overrides"] += document["identity_overrides"]

If retrieval of all pages takes longer that the polling interval, emit a warning log.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions