mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 13:05:32 +09:00
chore(repo): remove dead code and useless tests (#3375)
This commit is contained in:
1 parent
7e177a1c90
commit
1cd62eb661
1391 files changed
+783
-120415
No files matched your search
@@ -25,7 +25,6 @@ export interface IKVSubscription {
|
||||
unsubscribe(...channels: Array<string>): Promise<void>;
|
||||
quit(): Promise<void>;
|
||||
disconnect(): Promise<void>;
|
||||
removeAllListeners(event?: 'message' | 'error'): void;
|
||||
}
|
||||
|
||||
export interface KVPurgeBatchResult {
|
||||
@@ -78,22 +77,13 @@ export interface IKVProvider {
|
||||
ltrim(key: string, start: number, stop: number): Promise<void>;
|
||||
hset(key: string, field: string, value: string): Promise<number>;
|
||||
hdel(key: string, ...fields: Array<string>): Promise<number>;
|
||||
hget(key: string, field: string): Promise<string | null>;
|
||||
hgetall(key: string): Promise<Record<string, string>>;
|
||||
publish(channel: string, message: string): Promise<number>;
|
||||
duplicate(): IKVSubscription;
|
||||
acquireLock(key: string, token: string, ttlSeconds: number): Promise<boolean>;
|
||||
releaseLock(key: string, token: string): Promise<boolean>;
|
||||
extendLock(key: string, token: string, ttlSeconds: number): Promise<boolean>;
|
||||
renewSnowflakeNode(key: string, instanceId: string, ttlSeconds: number): Promise<boolean>;
|
||||
checkLeakyBucketLimit(key: string, limit: number, windowMs: number, cost: number): Promise<KVRateLimitResult>;
|
||||
tryConsumeTokens(
|
||||
key: string,
|
||||
requested: number,
|
||||
maxTokens: number,
|
||||
refillRate: number,
|
||||
refillIntervalMs: number,
|
||||
): Promise<number>;
|
||||
scheduleBulkDeletion(queueKey: string, secondaryKey: string, score: number, value: string): Promise<void>;
|
||||
claimBulkDeletion(queueKey: string, member: string, maxScore: number, leaseScore: number): Promise<boolean>;
|
||||
removeBulkDeletion(queueKey: string, secondaryKey: string, member?: string): Promise<boolean>;
|
||||
@@ -109,5 +99,4 @@ export interface IKVProvider {
|
||||
pipeline(): IKVPipeline;
|
||||
multi(): IKVPipeline;
|
||||
isClustered(): boolean;
|
||||
health(): Promise<boolean>;
|
||||
}
|
||||
@@ -65,52 +65,6 @@ if redis.call('GET', KEYS[1]) == ARGV[1] then
|
||||
end
|
||||
return 0
|
||||
`;
|
||||
const RENEW_SNOWFLAKE_SCRIPT = `
|
||||
if redis.call('GET', KEYS[1]) == ARGV[1] then
|
||||
redis.call('SET', KEYS[1], ARGV[1], 'EX', ARGV[2])
|
||||
return 1
|
||||
end
|
||||
return 0
|
||||
`;
|
||||
const TRY_CONSUME_TOKENS_SCRIPT = `
|
||||
${DECODE_BUCKET_STATE_SCRIPT}
|
||||
local key = KEYS[1]
|
||||
local now = tonumber(ARGV[1])
|
||||
local requested = tonumber(ARGV[2])
|
||||
local maxTokens = tonumber(ARGV[3])
|
||||
local refillRate = tonumber(ARGV[4])
|
||||
local refillIntervalMs = tonumber(ARGV[5])
|
||||
|
||||
local data = redis.call('GET', key)
|
||||
local tokens = maxTokens
|
||||
local lastRefill = now
|
||||
|
||||
if data then
|
||||
tokens, lastRefill = decodeBucketState(data, 'tokens', 'lastRefill')
|
||||
end
|
||||
|
||||
local elapsed = now - lastRefill
|
||||
if elapsed >= refillIntervalMs then
|
||||
local intervals = math.floor(elapsed / refillIntervalMs)
|
||||
local tokensToAdd = intervals * refillRate
|
||||
if tokensToAdd > 0 then
|
||||
tokens = math.min(maxTokens, tokens + tokensToAdd)
|
||||
lastRefill = now
|
||||
end
|
||||
end
|
||||
|
||||
local consumed = 0
|
||||
if tokens >= requested then
|
||||
consumed = requested
|
||||
tokens = tokens - requested
|
||||
elseif tokens > 0 then
|
||||
consumed = tokens
|
||||
tokens = 0
|
||||
end
|
||||
|
||||
redis.call('SET', key, cjson.encode({tokens = tokens, lastRefill = lastRefill}), 'EX', 3600)
|
||||
return consumed
|
||||
`;
|
||||
const CHECK_LEAKY_BUCKET_LIMIT_SCRIPT = `
|
||||
${DECODE_BUCKET_STATE_SCRIPT}
|
||||
local key = KEYS[1]
|
||||
@@ -324,15 +278,6 @@ export class KVClient implements IKVProvider {
|
||||
this.client.disconnect(false);
|
||||
}
|
||||
|
||||
async health(): Promise<boolean> {
|
||||
try {
|
||||
return (await this.execute('health', async () => this.client.ping())) === 'PONG';
|
||||
} catch (error) {
|
||||
this.logger.debug({error}, 'KV health check failed');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async get(key: string): Promise<string | null> {
|
||||
return await this.execute('get', async () => this.client.get(key));
|
||||
}
|
||||
@@ -571,10 +516,6 @@ export class KVClient implements IKVProvider {
|
||||
return await this.execute('hdel', async () => this.client.hdel(key, ...fields));
|
||||
}
|
||||
|
||||
async hget(key: string, field: string): Promise<string | null> {
|
||||
return await this.execute('hget', async () => this.client.hget(key, field));
|
||||
}
|
||||
|
||||
async hgetall(key: string): Promise<Record<string, string>> {
|
||||
return await this.execute('hgetall', async () => this.client.hgetall(key));
|
||||
}
|
||||
@@ -611,18 +552,6 @@ export class KVClient implements IKVProvider {
|
||||
return parseIntegerDecision(result, 'extendLock');
|
||||
}
|
||||
|
||||
async renewSnowflakeNode(key: string, instanceId: string, ttlSeconds: number): Promise<boolean> {
|
||||
const result = await this.executeScript(
|
||||
'renewSnowflakeNode',
|
||||
RENEW_SNOWFLAKE_SCRIPT,
|
||||
1,
|
||||
key,
|
||||
instanceId,
|
||||
ttlSeconds,
|
||||
);
|
||||
return parseIntegerDecision(result, 'renewSnowflakeNode');
|
||||
}
|
||||
|
||||
async checkLeakyBucketLimit(key: string, limit: number, windowMs: number, cost: number): Promise<KVRateLimitResult> {
|
||||
const result = await this.executeJsonScript(
|
||||
'checkLeakyBucketLimit',
|
||||
@@ -637,31 +566,6 @@ export class KVClient implements IKVProvider {
|
||||
return parseRateLimitResult(result);
|
||||
}
|
||||
|
||||
async tryConsumeTokens(
|
||||
key: string,
|
||||
requested: number,
|
||||
maxTokens: number,
|
||||
refillRate: number,
|
||||
refillIntervalMs: number,
|
||||
): Promise<number> {
|
||||
const now = Date.now();
|
||||
const result = await this.executeScript(
|
||||
'tryConsumeTokens',
|
||||
TRY_CONSUME_TOKENS_SCRIPT,
|
||||
1,
|
||||
key,
|
||||
now,
|
||||
requested,
|
||||
maxTokens,
|
||||
refillRate,
|
||||
refillIntervalMs,
|
||||
);
|
||||
if (!isNonNegativeSafeInteger(result) || result > requested) {
|
||||
throw createInvalidResponseError('tryConsumeTokens', 'an integer token count within the requested amount');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async scheduleBulkDeletion(queueKey: string, secondaryKey: string, score: number, value: string): Promise<void> {
|
||||
const result = await this.executeScript(
|
||||
'scheduleBulkDeletion',
|
||||
|
||||
@@ -258,15 +258,6 @@ export class KVSubscription implements IKVSubscription {
|
||||
}
|
||||
client.disconnect(false);
|
||||
}
|
||||
|
||||
removeAllListeners(event?: 'message' | 'error'): void {
|
||||
if (!event || event === 'message') {
|
||||
this.messageCallbacks.clear();
|
||||
}
|
||||
if (!event || event === 'error') {
|
||||
this.errorCallbacks.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createRetryStrategy(): (times: number) => number {
|
||||
|
||||
@@ -115,24 +115,12 @@ describe('KVClient script execution', () => {
|
||||
keyCount: 1,
|
||||
run: async (client) => client.extendLock('lock:key', 'token', 30),
|
||||
},
|
||||
{
|
||||
name: 'renewSnowflakeNode',
|
||||
reply: 1,
|
||||
keyCount: 1,
|
||||
run: async (client) => client.renewSnowflakeNode('snowflake:1', 'instance', 30),
|
||||
},
|
||||
{
|
||||
name: 'checkLeakyBucketLimit',
|
||||
reply: RATE_LIMIT_REPLY,
|
||||
keyCount: 1,
|
||||
run: async (client) => client.checkLeakyBucketLimit('rate_limit:bucket', 5, 1000, 1),
|
||||
},
|
||||
{
|
||||
name: 'tryConsumeTokens',
|
||||
reply: 2,
|
||||
keyCount: 1,
|
||||
run: async (client) => client.tryConsumeTokens('tokens:key', 2, 10, 1, 1000),
|
||||
},
|
||||
{
|
||||
name: 'scheduleBulkDeletion',
|
||||
reply: 1,
|
||||
|
||||
Reference in new issue
Block a user