ref
This commit is contained in:
1 parent
5a462ef158
commit
6e1770273e
2 files changed
+14
-7
No files matched your search
+11
-6
@@ -34,10 +34,13 @@ func (t *snapshotTask) Stop() {
|
||||
t.mx.Lock()
|
||||
if t.process {
|
||||
snapshotList := worker.takeSnapshot()
|
||||
defer func() {
|
||||
t.unload(snapshotList)
|
||||
t.wg.Wait()
|
||||
}()
|
||||
if len(snapshotList) != 0 {
|
||||
defer func() {
|
||||
t.wg.Add(1)
|
||||
t.unload(snapshotList)
|
||||
t.wg.Wait()
|
||||
}()
|
||||
}
|
||||
t.process = false
|
||||
t.close <- true
|
||||
}
|
||||
@@ -53,14 +56,16 @@ func (t *snapshotTask) run(timeout time.Duration) {
|
||||
return
|
||||
case <-t.timeout:
|
||||
list := worker.takeSnapshot()
|
||||
go t.unload(list)
|
||||
if len(list) > 0 {
|
||||
t.wg.Add(1)
|
||||
go t.unload(list)
|
||||
}
|
||||
t.timeout = time.After(timeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *snapshotTask) unload(list []entity.Snapshot) {
|
||||
t.wg.Add(1)
|
||||
if err := model.SnapshotRep.Update(list); err != nil {
|
||||
log.Error(log_code.ErrorSnapshotAccounting, err)
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ func (t *storingTask) Stop() {
|
||||
if t.counter != 0 {
|
||||
buffer := t.clearBuffer()
|
||||
defer func() {
|
||||
t.wg.Add(1)
|
||||
t.unload(buffer)
|
||||
t.wg.Wait()
|
||||
}()
|
||||
@@ -81,12 +82,14 @@ func (t *storingTask) run(timeout time.Duration) {
|
||||
case <-t.chanClose:
|
||||
return
|
||||
case cache := <-t.chanCounter:
|
||||
t.wg.Add(1)
|
||||
go t.unload(cache)
|
||||
t.chanTimeout = time.After(timeout)
|
||||
case <-t.chanTimeout:
|
||||
t.mx.Lock()
|
||||
if t.counter != 0 {
|
||||
buffer := t.clearBuffer()
|
||||
t.wg.Add(1)
|
||||
go t.unload(buffer)
|
||||
}
|
||||
t.mx.Unlock()
|
||||
@@ -96,7 +99,6 @@ func (t *storingTask) run(timeout time.Duration) {
|
||||
}
|
||||
|
||||
func (t *storingTask) unload(cache []entity.Request) {
|
||||
t.wg.Add(1)
|
||||
if err := model.RequestsRep.Insert(cache); err != nil {
|
||||
log.Error(log_code.ErrorUnloadAccounting, err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user