diff --git a/os/gtimer/gtimer.go b/os/gtimer/gtimer.go index dadbf61e5..ed295d75d 100644 --- a/os/gtimer/gtimer.go +++ b/os/gtimer/gtimer.go @@ -36,7 +36,7 @@ const ( panicExit = "exit" // Internal usage for custom job exit function with panic. defaultTimes = math.MaxInt32 // Default limit running times, a big number. defaultSlotNumber = 10 // Default slot number. - defaultWheelInterval = 60 // Default wheel interval. + defaultWheelInterval = 60 // Default wheel interval, for better manually reading. defaultWheelLevel = 5 // Default wheel level. cmdEnvKey = "gf.gtimer" // Configuration key for command argument or environment. ) diff --git a/os/gtimer/gtimer_entry.go b/os/gtimer/gtimer_entry.go index f64717d69..f413646c4 100644 --- a/os/gtimer/gtimer_entry.go +++ b/os/gtimer/gtimer_entry.go @@ -14,16 +14,17 @@ import ( // Entry is the timing job entry to wheel. type Entry struct { - name string - wheel *wheel // Belonged wheel. - job JobFunc // The job function. - singleton *gtype.Bool // Singleton mode. - status *gtype.Int // Job status. - times *gtype.Int // Limit running times. - intervalTicks int64 // The interval ticks of the job. - createTicks int64 // Timer ticks when the job installed. - createMs int64 // The timestamp in milliseconds when job installed. - intervalMs int64 // The interval milliseconds of the job. + name string + wheel *wheel // Belonged wheel. + job JobFunc // The job function. + singleton *gtype.Bool // Singleton mode. + status *gtype.Int // Job status. + times *gtype.Int // Limit running times. + intervalTicks int64 // The interval ticks of the job. + createTicks int64 // Timer ticks when the job installed. + createMs int64 // The timestamp in milliseconds when job installed. + intervalMs int64 // The interval milliseconds of the job. + installIntervalMs int64 // Interval when first installation in milliseconds. } // JobFunc is the job function. @@ -47,15 +48,16 @@ func (w *wheel) addEntry(interval time.Duration, job JobFunc, singleton bool, ti nowMs = time.Now().UnixNano() / 1e6 nowTicks = w.ticks.Val() entry = &Entry{ - wheel: w, - job: job, - times: gtype.NewInt(times), - status: gtype.NewInt(status), - createTicks: nowTicks, - intervalTicks: intervalTicks, - singleton: gtype.NewBool(singleton), - createMs: nowMs, - intervalMs: intervalMs, + wheel: w, + job: job, + times: gtype.NewInt(times), + status: gtype.NewInt(status), + createTicks: nowTicks, + intervalTicks: intervalTicks, + singleton: gtype.NewBool(singleton), + createMs: nowMs, + intervalMs: intervalMs, + installIntervalMs: intervalMs, } ) // Install the job to the list of the slot. @@ -73,16 +75,17 @@ func (w *wheel) addEntryByParent(rollOn bool, nowMs, interval int64, parent *Ent } nowTicks := w.ticks.Val() entry := &Entry{ - name: parent.name, - wheel: w, - job: parent.job, - times: parent.times, - status: parent.status, - intervalTicks: intervalTicks, - singleton: parent.singleton, - createTicks: nowTicks, - createMs: nowMs, - intervalMs: interval, + name: parent.name, + wheel: w, + job: parent.job, + times: parent.times, + status: parent.status, + intervalTicks: intervalTicks, + singleton: parent.singleton, + createTicks: nowTicks, + createMs: nowMs, + intervalMs: interval, + installIntervalMs: parent.installIntervalMs, } if rollOn { entry.createMs = parent.createMs diff --git a/os/gtimer/gtimer_loop.go b/os/gtimer/gtimer_loop.go index b6cf3ef4f..cfd936ee4 100644 --- a/os/gtimer/gtimer_loop.go +++ b/os/gtimer/gtimer_loop.go @@ -85,7 +85,7 @@ func (w *wheel) proceed() { if entry.Status() == StatusReset { entry.SetStatus(StatusReady) } - entry.wheel.timer.doAddEntryByParent(!runnable, nowMs, entry.intervalMs, entry) + entry.wheel.timer.doAddEntryByParent(!runnable, nowMs, entry.installIntervalMs, entry) } } }(l, n)