@@ -17,7 +17,6 @@ import (
1717 "opencsg.com/csghub-server/builder/deploy/common"
1818 "opencsg.com/csghub-server/builder/deploy/imagebuilder"
1919 "opencsg.com/csghub-server/builder/deploy/imagerunner"
20- "opencsg.com/csghub-server/builder/deploy/scheduler"
2120 "opencsg.com/csghub-server/builder/git/gitserver"
2221 "opencsg.com/csghub-server/builder/store/database"
2322 "opencsg.com/csghub-server/common/errorx"
@@ -32,12 +31,12 @@ const (
3231)
3332
3433const (
35- DeployStatusPending = 0
36- DeployStatusDeploying = 1
37- DeployStatusFailed = 2
38- DeployStatusStartUp = 3
39- DeployStatusRunning = 4
40- DeployStatusRunTimeError = 5
34+ DeployStatusPending = common . TaskStatusDeployPending
35+ DeployStatusDeploying = common . TaskStatusDeploying
36+ DeployStatusFailed = common . TaskStatusDeployFailed
37+ DeployStatusStartUp = common . TaskStatusDeployStartUp
38+ DeployStatusRunning = common . TaskStatusDeployRunning
39+ DeployStatusRunTimeError = common . TaskStatusDeployRunTimeError
4140)
4241
4342type DeployActivity struct {
@@ -145,7 +144,7 @@ func (a *DeployActivity) Build(ctx context.Context, taskId int64) error {
145144 if err != nil {
146145 return fmt .Errorf ("failed to get deploy task: %w" , err )
147146 }
148- if task .Status == scheduler . BuildSkip {
147+ if task .Status == common . TaskStatusBuildSkip {
149148 return nil
150149 }
151150 repoInfo , err := a .getRepositoryInfo (ctx , task )
@@ -173,7 +172,7 @@ func (a *DeployActivity) getLogger(ctx context.Context) log.Logger {
173172}
174173
175174// pollBuildStatus
176- func (a * DeployActivity ) pollBuildStatus (ctx context.Context , task * database.DeployTask , repoInfo scheduler .RepoInfo , buildRequest * types.ImageBuilderRequest ) error {
175+ func (a * DeployActivity ) pollBuildStatus (ctx context.Context , task * database.DeployTask , repoInfo common .RepoInfo , buildRequest * types.ImageBuilderRequest ) error {
177176 continueLoop , err := a .checkBuildStatus (ctx , task , buildRequest )
178177 if err != nil {
179178 return err
@@ -219,23 +218,28 @@ func (a *DeployActivity) checkBuildStatus(ctx context.Context, task *database.De
219218 }
220219
221220 switch {
222- case updatedTask .Status == scheduler . BuildPending :
221+ case updatedTask .Status == common . TaskStatusBuildPending :
223222 if err := a .ib .Build (ctx , buildRequest ); err != nil {
224223 if herr := a .handleBuildError (task , err ); herr != nil {
224+ a .getLogger (ctx ).Error ("Build failed" , "task_id" , task .ID , "error" , err )
225225 return false , herr
226226 }
227227
228+ a .getLogger (ctx ).Error ("Build failed" , "task_id" , task .ID , "error" , err )
228229 a .reportLog (types .BuildFailed .String ()+ ": \n " + err .Error (), types .StepBuildFailed , task )
229230 return false , fmt .Errorf ("build failed: %w" , err )
230231 }
231232 if err := a .handleBuildTaskToBuildInQueue (task ); err != nil {
233+ a .getLogger (ctx ).Error ("Failed to handle build task to build in queue" , "task_id" , task .ID , "error" , err )
232234 return false , err
233235 }
234236 a .reportLog (types .BuildInProgress .String (), types .StepBuildInProgress , task )
235237 return true , nil
236- case updatedTask .Status == scheduler .BuildFailed :
238+ case updatedTask .Status == common .TaskStatusBuildFailed :
239+ a .getLogger (ctx ).Info ("Build task failed" , "task_id" , task .ID , "status" , updatedTask .Status )
237240 return false , fmt .Errorf ("build task failed: %s" , updatedTask .Message )
238- case updatedTask .Status == scheduler .BuildSucceed :
241+ case updatedTask .Status == common .TaskStatusBuildSucceed :
242+ a .getLogger (ctx ).Info ("Build task succeed" , "task_id" , task .ID , "status" , updatedTask .Status )
239243 return false , nil
240244 case a .isTaskTimedOut (updatedTask ):
241245 a .reportLog ("build task timeout" , types .StepBuildFailed , task )
@@ -264,8 +268,8 @@ func (a *DeployActivity) isTaskTimedOut(task *database.DeployTask) bool {
264268}
265269
266270// getRepositoryInfo
267- func (a * DeployActivity ) getRepositoryInfo (ctx context.Context , task * database.DeployTask ) (scheduler .RepoInfo , error ) {
268- var repoInfo scheduler .RepoInfo
271+ func (a * DeployActivity ) getRepositoryInfo (ctx context.Context , task * database.DeployTask ) (common .RepoInfo , error ) {
272+ var repoInfo common .RepoInfo
269273
270274 if task .Deploy .SpaceID > 0 {
271275 space , err := a .ss .ByID (ctx , task .Deploy .SpaceID )
@@ -288,10 +292,10 @@ func (a *DeployActivity) getRepositoryInfo(ctx context.Context, task *database.D
288292}
289293
290294// createSpaceRepoInfo
291- func (a * DeployActivity ) createSpaceRepoInfo (space * database.Space , deployID int64 ) scheduler .RepoInfo {
295+ func (a * DeployActivity ) createSpaceRepoInfo (space * database.Space , deployID int64 ) common .RepoInfo {
292296 cloneInfo := utilcommon .BuildCloneInfoByDomain (a .cfg .PublicDomain , a .cfg .SSHDomain , space .Repository )
293297
294- return scheduler .RepoInfo {
298+ return common .RepoInfo {
295299 Path : space .Repository .Path ,
296300 Name : space .Repository .Name ,
297301 Sdk : space .Sdk ,
@@ -308,8 +312,8 @@ func (a *DeployActivity) createSpaceRepoInfo(space *database.Space, deployID int
308312}
309313
310314// createModelRepoInfo
311- func (a * DeployActivity ) createModelRepoInfo (model * database.Model , deployID int64 ) scheduler .RepoInfo {
312- return scheduler .RepoInfo {
315+ func (a * DeployActivity ) createModelRepoInfo (model * database.Model , deployID int64 ) common .RepoInfo {
316+ return common .RepoInfo {
313317 Path : model .Repository .Path ,
314318 Name : model .Repository .Name ,
315319 ModelID : model .ID ,
@@ -358,7 +362,7 @@ func (a *DeployActivity) updateTaskStatus(task *database.DeployTask) error {
358362
359363// handleRepositoryNotFound
360364func (a * DeployActivity ) handleRepositoryNotFound (task * database.DeployTask ) error {
361- task .Status = scheduler . BuildFailed
365+ task .Status = common . TaskStatusBuildFailed
362366 task .Message = "repository not found, please check the repository path"
363367 task .Deploy .Status = common .BuildFailed
364368 if err := a .updateTaskStatus (task ); err != nil {
@@ -370,7 +374,7 @@ func (a *DeployActivity) handleRepositoryNotFound(task *database.DeployTask) err
370374func (a * DeployActivity ) handleBuildCancelled (task * database.DeployTask ) error {
371375 ctx , cancel := context .WithTimeout (context .Background (), time .Second * time .Duration (5 ))
372376 defer cancel ()
373- task .Status = scheduler . Cancelled
377+ task .Status = common . TaskStatusCancelled
374378 task .Message = "Cancelled"
375379 if err := a .ds .UpdateDeployTask (ctx , task ); err != nil {
376380 return fmt .Errorf ("handleBuildCancelled failed to update deploy task status: %w" , err )
@@ -380,7 +384,7 @@ func (a *DeployActivity) handleBuildCancelled(task *database.DeployTask) error {
380384}
381385
382386func (a * DeployActivity ) handleBuildTaskTimeout (task * database.DeployTask ) error {
383- task .Status = scheduler . BuildFailed
387+ task .Status = common . TaskStatusBuildFailed
384388 task .Message = "build task timeout"
385389 task .Deploy .Status = common .BuildFailed
386390
@@ -393,7 +397,7 @@ func (a *DeployActivity) handleBuildTaskTimeout(task *database.DeployTask) error
393397
394398// handleBuildError
395399func (a * DeployActivity ) handleBuildError (task * database.DeployTask , err error ) error {
396- task .Status = scheduler . BuildFailed
400+ task .Status = common . TaskStatusBuildFailed
397401 task .Message = fmt .Sprintf ("build task failed: %s" , err .Error ())
398402 task .Deploy .Status = common .BuildFailed
399403
@@ -405,7 +409,7 @@ func (a *DeployActivity) handleBuildError(task *database.DeployTask, err error)
405409
406410// updateTaskStatusToBuildInQueue
407411func (a * DeployActivity ) handleBuildTaskToBuildInQueue (task * database.DeployTask ) error {
408- task .Status = scheduler . BuildInQueue
412+ task .Status = common . TaskStatusBuildInQueue
409413 task .Message = "build in queue"
410414 task .Deploy .Status = common .BuildInQueue
411415
@@ -455,7 +459,7 @@ func (a *DeployActivity) reportLog(message string, step types.Step, task *databa
455459}
456460
457461// createBuildRequest
458- func (a * DeployActivity ) createBuildRequest (ctx context.Context , task * database.DeployTask , repoInfo scheduler .RepoInfo ) (* types.ImageBuilderRequest , error ) {
462+ func (a * DeployActivity ) createBuildRequest (ctx context.Context , task * database.DeployTask , repoInfo common .RepoInfo ) (* types.ImageBuilderRequest , error ) {
459463 accessToken , err := a .ts .FindByUID (ctx , task .Deploy .UserID )
460464 if err != nil {
461465 return nil , fmt .Errorf ("failed to get git access token: %w" , err )
@@ -501,7 +505,7 @@ func (a *DeployActivity) createBuildRequest(ctx context.Context, task *database.
501505}
502506
503507// createDeployRequest
504- func (a * DeployActivity ) createDeployRequest (ctx context.Context , task * database.DeployTask , repoInfo scheduler .RepoInfo ) (* types.RunRequest , error ) {
508+ func (a * DeployActivity ) createDeployRequest (ctx context.Context , task * database.DeployTask , repoInfo common .RepoInfo ) (* types.RunRequest , error ) {
505509 logger := a .getLogger (ctx )
506510
507511 accessToken , err := a .ts .FindByUID (ctx , task .Deploy .UserID )
@@ -584,7 +588,7 @@ func (a *DeployActivity) createDeployRequest(ctx context.Context, task *database
584588 }, nil
585589}
586590
587- func (a * DeployActivity ) determineSDKVersion (repoInfo scheduler .RepoInfo ) string {
591+ func (a * DeployActivity ) determineSDKVersion (repoInfo common .RepoInfo ) string {
588592 if repoInfo .SdkVersion != "" {
589593 return repoInfo .SdkVersion
590594 }
@@ -606,7 +610,7 @@ func (a *DeployActivity) parseHardware(input string) string {
606610 return "cpu"
607611}
608612
609- func (a * DeployActivity ) stopBuild (buildTask * database.DeployTask , repoInfo scheduler .RepoInfo ) {
613+ func (a * DeployActivity ) stopBuild (buildTask * database.DeployTask , repoInfo common .RepoInfo ) {
610614 stopCtx , stopCancel := context .WithTimeout (context .Background (), 5 * time .Second )
611615 defer stopCancel ()
612616 paths := strings .Split (repoInfo .Path , "/" )
@@ -624,7 +628,7 @@ func (a *DeployActivity) stopBuild(buildTask *database.DeployTask, repoInfo sche
624628}
625629
626630// makeDeployEnv
627- func (a * DeployActivity ) makeDeployEnv (ctx context.Context , hardware types.HardWare , accessToken * database.AccessToken , deployInfo * database.Deploy , engineArgsTemplates []types.EngineArg , toolCallParsers map [string ]string , repoInfo scheduler .RepoInfo ) (map [string ]string , error ) {
631+ func (a * DeployActivity ) makeDeployEnv (ctx context.Context , hardware types.HardWare , accessToken * database.AccessToken , deployInfo * database.Deploy , engineArgsTemplates []types.EngineArg , toolCallParsers map [string ]string , repoInfo common .RepoInfo ) (map [string ]string , error ) {
628632 logger := a .getLogger (ctx )
629633
630634 envMap , err := utilcommon .JsonStrToMap (deployInfo .Env )
0 commit comments