Skip to main content

InfluxDBService

This item only works when running on the server. Server

Centralized service using serviceBag. Lets other packages share a single InfluxDBClient and, in tests, swap the underlying request implementation for an InfluxDBRequestHandlerMock at the ServiceBag layer -- the same pattern as PlayerDataStoreService.SetRobloxDataStore.

-- Production
local influxDBService = serviceBag:GetService(require("InfluxDBService"))
-- ...after Init, before first use...
influxDBService:SetClientConfig({ url = "https://example.com", token = "token" })

local writeAPI = influxDBService:GetWriteAPI("org", "bucket")
writeAPI:QueuePoint(point)
-- Tests: inject a mock so nothing hits the network
local requestMock = InfluxDBRequestHandlerMock.new()
influxDBService:SetRequestHandler(requestMock.Handler)

Functions

Init

InfluxDBService.Init(
serviceBagServiceBag
) → ()

Initializes the InfluxDBService. Should be done via ServiceBag.Init.

SetRequestHandler

InfluxDBService.SetRequestHandler(
requestHandlerInfluxDBRequestHandler
) → ()

Injects the request handler the underlying client uses to send data, instead of the real HttpPromise.request. Pass an InfluxDBRequestHandlerMock handler so tests never hit the network. Intended for testing; must be called before the client is first built.

HasRequestHandler

InfluxDBService.HasRequestHandler(selfInfluxDBService) → boolean

Returns whether a request handler override was injected (see InfluxDBService.SetRequestHandler). Consumers can use this to skip resolving real credentials when HTTP is intercepted.

SetClientConfig

InfluxDBService.SetClientConfig(
clientConfigInfluxDBClientConfig
) → ()

Sets the client config used to authenticate writes. May be called before or after the client is built; a later config is forwarded to the existing client.

GetClient

InfluxDBService.GetClient(selfInfluxDBService) → InfluxDBClient

Returns the shared InfluxDBClient, building it on first use with any injected request handler and client config.

GetWriteAPI

InfluxDBService.GetWriteAPI(
orgstring,
bucketstring,
precisionstring?
) → InfluxDBWriteAPI

Returns the write API for the given org and bucket from the shared client.

QueuePoint

InfluxDBService.QueuePoint(
orgstring,
bucketstring,
) → ()

Queues a point to the shared client's write API for the given org and bucket. Consumers should route queueing through this rather than holding the InfluxDBWriteAPI object: the service owns client teardown, so it can answer liveness -- a point queued after the service is destroyed errors, because it means the caller outlived teardown (the closing flush has already run; the caller should have been destroyed first).

PromiseFlushAll

InfluxDBService.PromiseFlushAll(selfInfluxDBService) → Promise<()>

Flushes every write API on the shared client. Resolves immediately if the client was never built.

Show raw api
{
    "functions": [
        {
            "name": "Init",
            "desc": "Initializes the InfluxDBService. Should be done via [ServiceBag.Init].",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                },
                {
                    "name": "serviceBag",
                    "desc": "",
                    "lua_type": "ServiceBag"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 57,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        },
        {
            "name": "SetRequestHandler",
            "desc": "Injects the request handler the underlying client uses to send data, instead of the real\n[HttpPromise.request]. Pass an [InfluxDBRequestHandlerMock] handler so tests never hit the network.\nIntended for testing; must be called before the client is first built.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                },
                {
                    "name": "requestHandler",
                    "desc": "",
                    "lua_type": "InfluxDBRequestHandler"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 69,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        },
        {
            "name": "HasRequestHandler",
            "desc": "Returns whether a request handler override was injected (see [InfluxDBService.SetRequestHandler]).\nConsumers can use this to skip resolving real credentials when HTTP is intercepted.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 85,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        },
        {
            "name": "SetClientConfig",
            "desc": "Sets the client config used to authenticate writes. May be called before or after the client is\nbuilt; a later config is forwarded to the existing client.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                },
                {
                    "name": "clientConfig",
                    "desc": "",
                    "lua_type": "InfluxDBClientConfig"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 95,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        },
        {
            "name": "GetClient",
            "desc": "Returns the shared [InfluxDBClient], building it on first use with any injected request handler and\nclient config.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "InfluxDBClient"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 114,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        },
        {
            "name": "GetWriteAPI",
            "desc": "Returns the write API for the given org and bucket from the shared client.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                },
                {
                    "name": "org",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "bucket",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "precision",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "InfluxDBWriteAPI"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 133,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        },
        {
            "name": "QueuePoint",
            "desc": "Queues a point to the shared client's write API for the given org and bucket. Consumers should\nroute queueing through this rather than holding the [InfluxDBWriteAPI] object: the service owns\nclient teardown, so it can answer liveness -- a point queued after the service is destroyed\nerrors, because it means the caller outlived teardown (the closing flush has already run; the\ncaller should have been destroyed first).",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                },
                {
                    "name": "org",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "bucket",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "point",
                    "desc": "",
                    "lua_type": "InfluxDBPoint"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 153,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        },
        {
            "name": "PromiseFlushAll",
            "desc": "Flushes every write API on the shared client. Resolves immediately if the client was never built.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "InfluxDBService"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<()>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 175,
                "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "InfluxDBService",
    "desc": "Centralized service using serviceBag. Lets other packages share a single [InfluxDBClient] and, in\ntests, swap the underlying request implementation for an [InfluxDBRequestHandlerMock] at the\nServiceBag layer -- the same pattern as [PlayerDataStoreService.SetRobloxDataStore].\n\n```lua\n-- Production\nlocal influxDBService = serviceBag:GetService(require(\"InfluxDBService\"))\n-- ...after Init, before first use...\ninfluxDBService:SetClientConfig({ url = \"https://example.com\", token = \"token\" })\n\nlocal writeAPI = influxDBService:GetWriteAPI(\"org\", \"bucket\")\nwriteAPI:QueuePoint(point)\n```\n\n```lua\n-- Tests: inject a mock so nothing hits the network\nlocal requestMock = InfluxDBRequestHandlerMock.new()\ninfluxDBService:SetRequestHandler(requestMock.Handler)\n```",
    "realm": [
        "Server"
    ],
    "source": {
        "line": 26,
        "path": "src/influxdbclient/src/Server/InfluxDBService.lua"
    }
}