feat: add redis gateway protection and task recovery
This commit is contained in:
1 parent
cbc7317aa8
commit
473479fc4c
17 files changed
+272
-10
No files matched your search
@@ -11,6 +11,8 @@ spring:
|
||||
data:
|
||||
redis:
|
||||
url: ${SPRING_DATA_REDIS_URL:redis://localhost:6379}
|
||||
connect-timeout: 2s
|
||||
timeout: 2s
|
||||
flyway:
|
||||
enabled: ${FLYWAY_ENABLED:true}
|
||||
baseline-on-migrate: true
|
||||
@@ -31,6 +33,13 @@ management:
|
||||
enabled: true
|
||||
|
||||
moyi:
|
||||
gateway:
|
||||
requests-per-minute: ${GATEWAY_REQUESTS_PER_MINUTE:60}
|
||||
reads-per-minute: ${GATEWAY_READS_PER_MINUTE:300}
|
||||
default-model-concurrency: ${GATEWAY_DEFAULT_MODEL_CONCURRENCY:4}
|
||||
tasks:
|
||||
max-queued-per-model: ${TASK_MAX_QUEUED_PER_MODEL:100}
|
||||
worker-interval-ms: ${MOYI_TASK_WORKER_INTERVAL_MS:1000}
|
||||
web:
|
||||
cors-origins: ${CONTROL_PLANE_CORS_ORIGINS:http://localhost:5173,http://127.0.0.1:5173}
|
||||
auth:
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
local time = redis.call('TIME')
|
||||
local now = tonumber(time[1]) * 1000 + math.floor(tonumber(time[2]) / 1000)
|
||||
redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', now)
|
||||
if redis.call('ZCARD', KEYS[1]) >= tonumber(ARGV[1]) then
|
||||
return 0
|
||||
end
|
||||
redis.call('ZADD', KEYS[1], now + tonumber(ARGV[2]), ARGV[3])
|
||||
redis.call('PEXPIRE', KEYS[1], ARGV[2])
|
||||
return 1
|
||||
@@ -0,0 +1,8 @@
|
||||
local count = redis.call('INCR', KEYS[1])
|
||||
if count == 1 then
|
||||
redis.call('PEXPIRE', KEYS[1], ARGV[2])
|
||||
end
|
||||
if count > tonumber(ARGV[1]) then
|
||||
return math.max(1, redis.call('PTTL', KEYS[1]))
|
||||
end
|
||||
return 0
|
||||
Reference in new issue
Block a user