fix(region): avoid panic when sync resources

This commit is contained in:
Qu Xuan
2021-04-22 16:23:01 +08:00
parent 56c3b704fc
commit 568687c436
2 changed files with 3 additions and 1 deletions
+2 -1
View File
@@ -17,6 +17,7 @@ package cronman
import (
"container/heap"
"context"
"fmt"
"runtime/debug"
"sync"
"time"
@@ -393,7 +394,7 @@ func (job *SCronJob) runJobInWorker(isStart bool) {
log.Debugf("Cron job: %s started", job.Name)
ctx := context.Background()
ctx = context.WithValue(ctx, appctx.APP_CONTEXT_KEY_APPNAME, "Cron-Service")
ctx = context.WithValue(ctx, appctx.APP_CONTEXT_KEY_TASKNAME, job.Name)
ctx = context.WithValue(ctx, appctx.APP_CONTEXT_KEY_TASKNAME, fmt.Sprintf("%s-%d", job.Name, time.Now().Unix()))
userCred := DefaultAdminSessionGenerator()
job.job(ctx, userCred, isStart)
}
@@ -431,6 +431,7 @@ func (self *SCloudproviderregion) submitSyncTask(ctx context.Context, userCred m
self.markStartSync(userCred)
RunSyncCloudproviderRegionTask(ctx, self.getSyncTaskKey(), func() {
nopanic.Run(func() {
ctx = context.WithValue(ctx, "provider-region", fmt.Sprintf("%d", self.RowId))
err := self.DoSync(ctx, userCred, syncRange)
if err != nil {
log.Errorf("DoSync faild %v", err)