Browse Source

事件增加调试日志

gitlink
Sydonian 2 years ago
parent
commit
962dc084dc
3 changed files with 30 additions and 15 deletions
  1. +13
    -8
      internal/event/check_cache.go
  2. +3
    -2
      internal/event/check_state.go
  3. +14
    -5
      internal/event/check_storage.go

+ 13
- 8
internal/event/check_cache.go View File

@@ -47,11 +47,12 @@ func (t *CheckCache) TryMerge(other Event) bool {
}

func (t *CheckCache) Execute(execCtx ExecuteContext) {
logger.Debugf("begin check cache")
log := logger.WithType[CheckCache]("Event")
log.Debugf("begin with %v", logger.FormatStruct(t))

filesMap, err := execCtx.Args.IPFS.GetPinnedFiles()
if err != nil {
logger.Warnf("get pinned files from ipfs failed, err: %s", err.Error())
log.Warnf("get pinned files from ipfs failed, err: %s", err.Error())
return
}

@@ -64,6 +65,8 @@ func (t *CheckCache) Execute(execCtx ExecuteContext) {
}

func (t *CheckCache) checkIncrement(filesMap map[string]shell.PinInfo, execCtx ExecuteContext) {
log := logger.WithType[CheckCache]("Event")

var updateCacheOps []scevt.UpdateCacheEntry

for _, cache := range t.Caches {
@@ -74,7 +77,7 @@ func (t *CheckCache) checkIncrement(filesMap map[string]shell.PinInfo, execCtx E
} else if cache.State == consts.CACHE_STATE_TEMP {
err := execCtx.Args.IPFS.Unpin(cache.FileHash)
if err != nil {
logger.WithField("FileHash", cache.FileHash).Warnf("unpin file failed, err: %s", err.Error())
log.WithField("FileHash", cache.FileHash).Warnf("unpin file failed, err: %s", err.Error())
}
}

@@ -86,7 +89,7 @@ func (t *CheckCache) checkIncrement(filesMap map[string]shell.PinInfo, execCtx E
// TODO 需要考虑此处是否是同步的过程
err := execCtx.Args.IPFS.Pin(cache.FileHash)
if err != nil {
logger.WithField("FileHash", cache.FileHash).Warnf("pin file failed, err: %s", err.Error())
log.WithField("FileHash", cache.FileHash).Warnf("pin file failed, err: %s", err.Error())
}

} else if cache.State == consts.CACHE_STATE_TEMP {
@@ -108,12 +111,14 @@ func (t *CheckCache) checkIncrement(filesMap map[string]shell.PinInfo, execCtx E
if err == nil {
execCtx.Args.Scanner.PostEvent(evtmsg)
} else {
logger.Warnf("new post event body failed, err: %s", err.Error())
log.Warnf("new post event body failed, err: %s", err.Error())
}
}
}

func (t *CheckCache) checkComplete(filesMap map[string]shell.PinInfo, execCtx ExecuteContext) {
log := logger.WithType[CheckCache]("Event")

var updateCacheOps []scevt.UpdateCacheEntry

for _, cache := range t.Caches {
@@ -124,7 +129,7 @@ func (t *CheckCache) checkComplete(filesMap map[string]shell.PinInfo, execCtx Ex
} else if cache.State == consts.CACHE_STATE_TEMP {
err := execCtx.Args.IPFS.Unpin(cache.FileHash)
if err != nil {
logger.WithField("FileHash", cache.FileHash).Warnf("unpin file failed, err: %s", err.Error())
log.WithField("FileHash", cache.FileHash).Warnf("unpin file failed, err: %s", err.Error())
}
}

@@ -136,7 +141,7 @@ func (t *CheckCache) checkComplete(filesMap map[string]shell.PinInfo, execCtx Ex
// TODO 需要考虑此处是否是同步的过程
err := execCtx.Args.IPFS.Pin(cache.FileHash)
if err != nil {
logger.WithField("FileHash", cache.FileHash).Warnf("pin file failed, err: %s", err.Error())
log.WithField("FileHash", cache.FileHash).Warnf("pin file failed, err: %s", err.Error())
}

} else if cache.State == consts.CACHE_STATE_TEMP {
@@ -160,7 +165,7 @@ func (t *CheckCache) checkComplete(filesMap map[string]shell.PinInfo, execCtx Ex
if err == nil {
execCtx.Args.Scanner.PostEvent(evtmsg)
} else {
logger.Warnf("new post event body failed, err: %s", err.Error())
log.Warnf("new post event body failed, err: %s", err.Error())
}
}



+ 3
- 2
internal/event/check_state.go View File

@@ -22,7 +22,8 @@ func (t *CheckState) TryMerge(other Event) bool {
}

func (t *CheckState) Execute(execCtx ExecuteContext) {
logger.Debugf("begin check state")
log := logger.WithType[CheckState]("Event")
log.Debugf("begin")

ipfsStatus := consts.IPFS_STATUS_OK

@@ -35,7 +36,7 @@ func (t *CheckState) Execute(execCtx ExecuteContext) {
if err == nil {
execCtx.Args.Scanner.PostEvent(evtmsg)
} else {
logger.Warnf("new post event body failed, err: %s", err.Error())
log.Warnf("new post event body failed, err: %s", err.Error())
}
}



+ 14
- 5
internal/event/check_storage.go View File

@@ -33,6 +33,10 @@ func (t *CheckStorage) TryMerge(other Event) bool {
return false
}

if event.StorageID != t.StorageID {
return false
}

if event.IsComplete {
t.IsComplete = true
t.Objects = event.Objects
@@ -49,13 +53,14 @@ func (t *CheckStorage) TryMerge(other Event) bool {
}

func (t *CheckStorage) Execute(execCtx ExecuteContext) {
logger.Debugf("begin check storage")
log := logger.WithType[CheckStorage]("Event")
log.Debugf("begin with %v", logger.FormatStruct(t))

dirFullPath := filepath.Join(config.Cfg().StorageBaseDir, t.Directory)

infos, err := ioutil.ReadDir(dirFullPath)
if err != nil {
logger.Warnf("list storage directory failed, err: %s", err.Error())
log.Warnf("list storage directory failed, err: %s", err.Error())

evtmsg, err := scmsg.NewPostEventBody(scevt.NewUpdateStorage(
t.StorageID,
@@ -65,7 +70,7 @@ func (t *CheckStorage) Execute(execCtx ExecuteContext) {
if err == nil {
execCtx.Args.Scanner.PostEvent(evtmsg)
} else {
logger.Warnf("new post event body failed, err: %s", err.Error())
log.Warnf("new post event body failed, err: %s", err.Error())
}
return
}
@@ -80,6 +85,8 @@ func (t *CheckStorage) Execute(execCtx ExecuteContext) {
}

func (t *CheckStorage) checkIncrement(fileInfos []fs.FileInfo, execCtx ExecuteContext) {
log := logger.WithType[CheckStorage]("Event")

infosMap := make(map[string]fs.FileInfo)
for _, info := range fileInfos {
infosMap[info.Name()] = info
@@ -110,11 +117,13 @@ func (t *CheckStorage) checkIncrement(fileInfos []fs.FileInfo, execCtx ExecuteCo
if err == nil {
execCtx.Args.Scanner.PostEvent(evtmsg)
} else {
logger.Warnf("new post event body failed, err: %s", err.Error())
log.Warnf("new post event body failed, err: %s", err.Error())
}
}

func (t *CheckStorage) checkComplete(fileInfos []fs.FileInfo, execCtx ExecuteContext) {
log := logger.WithType[CheckStorage]("Event")

infosMap := make(map[string]fs.FileInfo)
for _, info := range fileInfos {
infosMap[info.Name()] = info
@@ -145,7 +154,7 @@ func (t *CheckStorage) checkComplete(fileInfos []fs.FileInfo, execCtx ExecuteCon
if err == nil {
execCtx.Args.Scanner.PostEvent(evtmsg)
} else {
logger.Warnf("new post event body failed, err: %s", err.Error())
log.Warnf("new post event body failed, err: %s", err.Error())
}
}



Loading…
Cancel
Save