UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

39 lines (36 loc) 1.13 kB
/** * @module CircuitBreaker */ /** * @internal */ export const circuitBreakerStorageLua = ` -- @template TMetrics -- @param circuitBreakerPolicy InternalCircuitBreakerPolicy<TMetrics> -- @param currentDate number local function CircuitBreakerStorage(circuitBreakerPolicy, currentDate) -- @param key string -- @param AllCircuitBreakerState<TMetrics> local function find(key) if redis.call("EXISTS", key) == 1 then local value = redis.call("GET", key) return cjson.decode(value) end return circuitBreakerPolicy.initialState() end return { -- @param key string -- @param update DatabaseCircuitBreakerUpdateStateFn<TMetrics> atomicUpdate = function(key, update) local currentState = find(key) local newState = update(currentState, currentDate) redis.call("set", key, cjson.encode(newState)) return { from = currentState.type, to = newState.type, } end } end `; //# sourceMappingURL=circuit-breaker-storage-lua.js.map