Skip to content

Commit 637f8f9

Browse files
authored
fix: clean not do not concurrent (#93)
* fix: clean not do not concurrent * fix
1 parent 9ebe5bd commit 637f8f9

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ docker-compose up -d
110110
- `LOG_DETAIL_REQUEST_BODY_MAX_SIZE`: Maximum size for request body in log details, default is `128KB`
111111
- `LOG_DETAIL_RESPONSE_BODY_MAX_SIZE`: Maximum size for response body in log details, default is `128KB`
112112
- `LOG_DETAIL_STORAGE_HOURS`: Hours to store log details, default is `72` (3 days)
113-
- `CLEAN_LOG_BATCH_SIZE`: Batch size for cleaning logs, default is `2000`
113+
- `CLEAN_LOG_BATCH_SIZE`: Batch size for cleaning logs, cleaning interval is 1 minute, default is `2000`
114114

115115
### Service Control
116116

README.zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ docker-compose up -d
111111
- `LOG_DETAIL_REQUEST_BODY_MAX_SIZE`: 日志详情请求体最大大小,默认 `128KB`
112112
- `LOG_DETAIL_RESPONSE_BODY_MAX_SIZE`: 日志详情响应体最大大小,默认 `128KB`
113113
- `LOG_DETAIL_STORAGE_HOURS`: 日志详情存储时间,默认 `72`(3 天)
114-
- `CLEAN_LOG_BATCH_SIZE`: 日志清理批量大小,默认 `2000`
114+
- `CLEAN_LOG_BATCH_SIZE`: 日志清理批量大小,清理间隔一分钟,默认 `2000`
115115

116116
### 服务控制
117117

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,17 @@ func DetectIPGroups() {
243243
func cleanLog(ctx context.Context) {
244244
log.Info("clean log start")
245245
// the interval should not be too large to avoid cleaning too much at once
246-
ticker := time.NewTicker(time.Second * 15)
246+
ticker := time.NewTicker(time.Minute)
247247
defer ticker.Stop()
248248

249249
for {
250250
select {
251251
case <-ctx.Done():
252252
return
253253
case <-ticker.C:
254+
if !trylock.Lock("cleanLog", time.Minute) {
255+
continue
256+
}
254257
optimize := trylock.Lock("optimizeLog", time.Hour*24)
255258
err := model.CleanLog(int(config.GetCleanLogBatchSize()), optimize)
256259
if err != nil {

model/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func cleanLog(batchSize int, optimize bool) error {
266266
"created_at < ?",
267267
time.Now().Truncate(time.Hour).Add(-time.Duration(logContentStorageHours)*time.Hour),
268268
).
269-
Where("endpoint IS NOT NULL").
269+
Where("content IS NOT NULL").
270270
Order("created_at DESC").
271271
Limit(1).
272272
Select("id").

0 commit comments

Comments
 (0)