MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Start

Method Start

internal/metrics/task_sqlite.go:186–234  ·  view source on GitHub ↗

Start 启动任务

()

Source from the content-addressed store, hash-verified

184
185// Start 启动任务
186func (this *SQLiteTask) Start() error {
187 // 读取数据
188 this.statsTicker = utils.NewTicker(1 * time.Minute)
189 goman.New(func() {
190 for this.statsTicker.Next() {
191 var tr = trackers.Begin("METRIC:DUMP_STATS_TO_LOCAL_DATABASE")
192
193 this.statsLocker.Lock()
194 var statsMap = this.statsMap
195 this.statsMap = map[string]*Stat{}
196 this.statsLocker.Unlock()
197
198 for _, stat := range statsMap {
199 err := this.InsertStat(stat)
200 if err != nil {
201 remotelogs.Error("METRIC", "insert stat failed: "+err.Error())
202 }
203 }
204
205 tr.End()
206 }
207 })
208
209 // 清理
210 this.cleanTicker = time.NewTicker(24 * time.Hour)
211 goman.New(func() {
212 idles.RunTicker(this.cleanTicker, func() {
213 var tr = trackers.Begin("METRIC:CLEAN_EXPIRED")
214 err := this.CleanExpired()
215 tr.End()
216 if err != nil {
217 remotelogs.Error("METRIC", "clean expired stats failed: "+err.Error())
218 }
219 })
220 })
221
222 // 上传
223 this.uploadTicker = utils.NewTicker(this.itemConfig.UploadDuration())
224 goman.New(func() {
225 for this.uploadTicker.Next() {
226 err := this.Upload(1 * time.Second)
227 if err != nil && !rpc.IsConnError(err) {
228 remotelogs.Error("METRIC", "upload stats failed: "+err.Error())
229 }
230 }
231 })
232
233 return nil
234}
235
236// Stop 停止任务
237func (this *SQLiteTask) Stop() error {

Callers

nothing calls this directly

Calls 14

InsertStatMethod · 0.95
CleanExpiredMethod · 0.95
UploadMethod · 0.95
NewTickerFunction · 0.92
NewFunction · 0.92
BeginFunction · 0.92
ErrorFunction · 0.92
RunTickerFunction · 0.92
IsConnErrorFunction · 0.92
NextMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected