fix: 设置分布式锁超时1分钟解除

This commit is contained in:
TsMask
2025-10-14 11:07:08 +08:00
parent 45b6263679
commit 654c251929
18 changed files with 21 additions and 18 deletions

View File

@@ -51,7 +51,7 @@ func (s *BackupExportCDRProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:backup_export_cdr:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -51,7 +51,7 @@ func (s *BackupExportKPIProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:backup_export_kpi:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -46,7 +46,7 @@ func (s *BackupExportLogProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:backup_export_log:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -57,7 +57,7 @@ func (s *BackupExportTableProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:backup_export_table:%d:%s", sysJob.JobId, params.TableName)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -50,7 +50,7 @@ func (s *BackupExportUDMProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:backup_export_udm:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -41,7 +41,7 @@ func (s *BackupRemoveFileProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:backup_remove_file:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -32,7 +32,7 @@ func (s *DeleteAlarmRecordProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:delete_alarm_record:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -33,7 +33,7 @@ func (s *DeleteCDRRecordProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:delete_cdr_record:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -55,7 +55,7 @@ func (s *DeleteDataRecordProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:delete_data_record:%d:%s", sysJob.JobId, params.TableName)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -33,7 +33,7 @@ func (s *DeleteKPIRecordProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:delete_kpi_record:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -40,7 +40,7 @@ func (s *DeleteNeConfigBackupProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:delete_ne_config_backup:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -33,7 +33,7 @@ func (s *DeleteUENBRecordProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:delete_uenb_record:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -3,6 +3,7 @@ package monitor_sys_resource
import (
"encoding/json"
"fmt"
"time"
"be.ems/src/framework/cron"
"be.ems/src/framework/database/redis"
@@ -34,7 +35,7 @@ func (s *MonitorSysResourceProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:monitor_sys_resource:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -53,7 +53,7 @@ func (s *NeAlarmStateCheckProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:ne_alarm_state_check:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -74,7 +74,7 @@ func (s *NeAlarmStateCheckCMDProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:ne_alarm_state_check_cmd:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -55,7 +55,7 @@ func (s *NeAlarmStateCheckLicenseProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:ne_alarm_state_check_license:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -3,6 +3,7 @@ package ne_config_backup
import (
"fmt"
"path/filepath"
"time"
"be.ems/src/framework/cron"
"be.ems/src/framework/database/redis"
@@ -39,7 +40,7 @@ func (s *NeConfigBackupProcessor) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:ne_config_backup:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)

View File

@@ -2,6 +2,7 @@ package ne_data_udm
import (
"fmt"
"time"
"be.ems/src/framework/cron"
"be.ems/src/framework/database/redis"
@@ -38,7 +39,7 @@ func (s *NeDataUDM) Execute(data any) (any, error) {
// 分布式锁,防止多个任务同时执行
lockKey := fmt.Sprintf("processor:ne_data_udm:%d", sysJob.JobId)
if ok := redis.SetNX("", lockKey, 0); !ok {
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
return nil, cron.ErrTaskRunning
}
defer redis.Del("", lockKey)