Optimize code

This commit is contained in:
Wang Guoliang
2018-01-24 13:43:51 +08:00
committed by Ta-Ching Chen
parent 01bcfad44a
commit b578819202
11 changed files with 21 additions and 21 deletions
+1 -1
View File
@@ -237,7 +237,7 @@ func TestExecutor(t *testing.T) {
if err != nil {
log.Panicf("failed to get func svc: %v", err)
}
log.Printf("svc for function created at: %v (in %v)", svc, time.Now().Sub(t1))
log.Printf("svc for function created at: %v (in %v)", svc, time.Since(t1))
// ensure that a pod with the label functionName=f.Metadata.Name exists
podCount := countPods(kubeClient, functionNs, map[string]string{"functionName": f.Metadata.Name})
+2 -2
View File
@@ -100,7 +100,7 @@ func (fsc *FunctionServiceCache) service() {
for _, funcSvc := range fscs {
fsvc := funcSvc.(*FuncSvc)
if fsvc.Environment.Metadata.UID == req.env.UID &&
time.Now().Sub(fsvc.Atime) > req.age {
time.Since(fsvc.Atime) > req.age {
funcObjects = append(funcObjects, fsvc)
}
}
@@ -196,7 +196,7 @@ func (fsc *FunctionServiceCache) _touchByAddress(address string) error {
}
func (fsc *FunctionServiceCache) DeleteOld(fsvc *FuncSvc, minAge time.Duration) (bool, error) {
if time.Now().Sub(fsvc.Atime) < minAge {
if time.Since(fsvc.Atime) < minAge {
return false, nil
}
+3 -3
View File
@@ -198,7 +198,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
startTime := time.Now()
for {
// Retries took too long, error out.
if time.Now().Sub(startTime) > gp.podReadyTimeout {
if time.Since(startTime) > gp.podReadyTimeout {
log.Printf("[%v] Erroring out, timed out", newLabels)
return nil, errors.New("timeout: waited too long to get a ready pod")
}
@@ -260,7 +260,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
continue
}
}
log.Printf("Chosen pod: %v (in %v)", chosenPod.ObjectMeta.Name, time.Now().Sub(startTime))
log.Printf("Chosen pod: %v (in %v)", chosenPod.ObjectMeta.Name, time.Since(startTime))
return chosenPod, nil
}
}
@@ -510,7 +510,7 @@ func (gp *GenericPool) waitForReadyPod() error {
return nil
}
if time.Now().Sub(startTime) > gp.podReadyTimeout {
if time.Since(startTime) > gp.podReadyTimeout {
return errors.New("timeout: waited too long for pod to be ready")
}
time.Sleep(1000 * time.Millisecond)