SoFunction
Updated on 2025-03-04

golang implements the execution of a function every few minutes

1. Use the timer

2. Use this method

go function() 
func function() {
 // TODO specific logic 
 // Perform every 5 minutes (5*, function)
}

Supplement: Golang: Perform operations at zero o'clock every day

I won't say much nonsense, let's just read the code~

import (
  "time"
  "fmt"
)
//Timely settlement of Boottime table datafunc BoottimeTimingSettlement() {
  for {
    now := ()
    // Calculate the next zero point    next := ( * 24)
    next = ((), (), (), 0, 0, 0, 0, ())
    t := ((now))
    <-
    Printf("Timely settlement of Boottime table data, settlement is completed: %v\n",())
    //The following are the operations performed regularly    BoottimeSettlement()
  }
}

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.