Browse Source

定时任务增加随机启动延时

gitlink
Sydonian 2 years ago
parent
commit
015bfd8c1c
2 changed files with 8 additions and 6 deletions
  1. +2
    -0
      internal/tickevent/tick_event.go
  2. +6
    -6
      main.go

+ 2
- 0
internal/tickevent/tick_event.go View File

@@ -11,6 +11,8 @@ type ExecuteArgs struct {
DB *mydb.DB
}

type StartOption = tickevent.StartOption

type Executor = tickevent.Executor[ExecuteArgs]

type ExecuteContext = tickevent.ExecuteContext[ExecuteArgs]


+ 6
- 6
main.go View File

@@ -87,15 +87,15 @@ func serveScannerServer(server *scsvr.ScannerServer, wg *sync.WaitGroup) {
func startTickEvent(tickExecutor *tickevent.Executor) {
// TODO 可以考虑增加配置文件,配置这些任务间隔时间

tickExecutor.Start(tickevent.NewBatchAllAgentCheckCache(), 5*60*1000)
tickExecutor.Start(tickevent.NewBatchAllAgentCheckCache(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000})

tickExecutor.Start(tickevent.NewBatchCheckAllObject(), 5*60*1000)
tickExecutor.Start(tickevent.NewBatchCheckAllObject(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000})

tickExecutor.Start(tickevent.NewBatchCheckAllRepCount(), 5*60*1000)
tickExecutor.Start(tickevent.NewBatchCheckAllRepCount(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000})

tickExecutor.Start(tickevent.NewBatchCheckAllStorage(), 5*60*1000)
tickExecutor.Start(tickevent.NewBatchCheckAllStorage(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000})

//tickExecutor.Start(tickevent.NewCheckAgentState(), 5*60*1000)
//tickExecutor.Start(tickevent.NewCheckAgentState(), 5*60*1000, tickevent.StartOption{RandomFirstStartDelayMs: 60 * 1000})

tickExecutor.Start(tickevent.NewCheckCache(), 5*60*1000)
tickExecutor.Start(tickevent.NewCheckCache(), 5*60*1000, tickevent.StartOption{RandomStartDelayMs: 60 * 1000})
}

Loading…
Cancel
Save