package task import ( "context" "adm-ads/errors" "fmt" "time" "adm-ads/common.in/utils" ) type Task func() error func Do(ctx context.Context, tasks ...Task) (returnErr error) { utils.GC() if utils.ExitRecieved == true { return errors.SystemError } // 开始时间 startTime := uint64(time.Now().UnixNano()) // 抓异常代码 defer func() { status := "SUCCESS" if r := recover(); r != nil { if e, ok := r.(error); ok { returnErr = e } else { returnErr = fmt.Errorf("%+v", r) } } if returnErr != nil { status = "FAIL" } printAccessLog(ctx, startTime, status) }() for _, task := range tasks { if task != nil { if err := task(); err != nil { returnErr = err return } } } return }