Skip to content

Commit 4bf69cd

Browse files
committed
fix
1 parent d05383d commit 4bf69cd

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

builder/deploy/deployer.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Deployer interface {
3838
UpdateCluster(ctx context.Context, data types.ClusterRequest) (*types.UpdateClusterResponse, error)
3939
UpdateDeploy(ctx context.Context, dur *types.DeployUpdateReq, deploy *database.Deploy) error
4040
StartDeploy(ctx context.Context, deploy *database.Deploy) error
41-
CheckResourceAvailable(ctx context.Context, clusterId string, orderDetailID int64, hardWare *types.HardWare) (bool, error)
41+
CheckResourceAvailable(ctx context.Context, clusterId string, hardWare *types.HardWare) (bool, error)
4242
SubmitEvaluation(ctx context.Context, req types.EvaluationReq) (*types.ArgoWorkFlowRes, error)
4343
ListEvaluations(context.Context, string, int, int) (*types.ArgoWorkFlowListRes, error)
4444
DeleteEvaluation(ctx context.Context, req types.ArgoWorkFlowDeleteReq) error
@@ -83,15 +83,13 @@ func newDeployer(s scheduler.Scheduler, ib imagebuilder.Builder, ir imagerunner.
8383
}
8484

8585
go d.refreshStatus()
86-
if d.c.IsMasterHost {
87-
go func() {
88-
err = d.s.Run()
89-
if err != nil {
90-
slog.Error("run scheduler failed", slog.Any("error", err))
91-
}
92-
}()
93-
go d.startAccounting()
94-
}
86+
go func() {
87+
err = d.s.Run()
88+
if err != nil {
89+
slog.Error("run scheduler failed", slog.Any("error", err))
90+
}
91+
}()
92+
go d.startAccounting()
9593
return d, nil
9694
}
9795

builder/store/database/argo_workflow.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,33 @@ import (
99
"opencsg.com/csghub-server/common/types"
1010
)
1111

12-
type ArgoWorkFlowStore struct {
12+
type argoWorkFlowStoreImpl struct {
1313
db *DB
1414
}
1515

16-
func NewArgoWorkFlowStore() *ArgoWorkFlowStore {
17-
return &ArgoWorkFlowStore{
16+
type ArgoWorkFlowStore interface {
17+
FindByID(ctx context.Context, id int64) (WorkFlow ArgoWorkflow, err error)
18+
FindByTaskID(ctx context.Context, id string) (WorkFlow ArgoWorkflow, err error)
19+
FindByUsername(ctx context.Context, username string, per, page int) (WorkFlows []ArgoWorkflow, total int, err error)
20+
CreateWorkFlow(ctx context.Context, workFlow ArgoWorkflow) (*ArgoWorkflow, error)
21+
// mainly for update status
22+
UpdateWorkFlow(ctx context.Context, workFlow ArgoWorkflow) (*ArgoWorkflow, error)
23+
// delete workflow by id
24+
DeleteWorkFlow(ctx context.Context, id int64) error
25+
}
26+
27+
func NewArgoWorkFlowStore() ArgoWorkFlowStore {
28+
return &argoWorkFlowStoreImpl{
1829
db: defaultDB,
1930
}
2031
}
2132

33+
func NewArgoWorkFlowStoreWithDB(db *DB) ArgoWorkFlowStore {
34+
return &argoWorkFlowStoreImpl{
35+
db: db,
36+
}
37+
}
38+
2239
type ArgoWorkflow struct {
2340
ID int64 `bun:",pk,autoincrement" json:"id"`
2441
Username string `bun:",notnull" json:"username"`
@@ -45,23 +62,23 @@ type ArgoWorkflow struct {
4562
FailuresURL string `bun:"," json:"failures_url"`
4663
}
4764

48-
func (s *ArgoWorkFlowStore) FindByID(ctx context.Context, id int64) (WorkFlow ArgoWorkflow, err error) {
65+
func (s *argoWorkFlowStoreImpl) FindByID(ctx context.Context, id int64) (WorkFlow ArgoWorkflow, err error) {
4966
err = s.db.Operator.Core.NewSelect().Model(&WorkFlow).Where("id = ?", id).Scan(ctx, &WorkFlow)
5067
if err != nil {
5168
return
5269
}
5370
return
5471
}
5572

56-
func (s *ArgoWorkFlowStore) FindByTaskID(ctx context.Context, id string) (WorkFlow ArgoWorkflow, err error) {
73+
func (s *argoWorkFlowStoreImpl) FindByTaskID(ctx context.Context, id string) (WorkFlow ArgoWorkflow, err error) {
5774
err = s.db.Operator.Core.NewSelect().Model(&WorkFlow).Where("task_id = ?", id).Scan(ctx, &WorkFlow)
5875
if err != nil {
5976
return
6077
}
6178
return
6279
}
6380

64-
func (s *ArgoWorkFlowStore) FindByUsername(ctx context.Context, username string, per, page int) (WorkFlows []ArgoWorkflow, total int, err error) {
81+
func (s *argoWorkFlowStoreImpl) FindByUsername(ctx context.Context, username string, per, page int) (WorkFlows []ArgoWorkflow, total int, err error) {
6582
query := s.db.Operator.Core.
6683
NewSelect().
6784
Model(&WorkFlows).
@@ -82,7 +99,7 @@ func (s *ArgoWorkFlowStore) FindByUsername(ctx context.Context, username string,
8299
return
83100
}
84101

85-
func (s *ArgoWorkFlowStore) CreateWorkFlow(ctx context.Context, workFlow ArgoWorkflow) (*ArgoWorkflow, error) {
102+
func (s *argoWorkFlowStoreImpl) CreateWorkFlow(ctx context.Context, workFlow ArgoWorkflow) (*ArgoWorkflow, error) {
86103
res, err := s.db.Core.NewInsert().Model(&workFlow).Exec(ctx, &workFlow)
87104
if err := assertAffectedOneRow(res, err); err != nil {
88105
return nil, fmt.Errorf("failed to save WorkFlow in db, error:%w", err)
@@ -92,13 +109,13 @@ func (s *ArgoWorkFlowStore) CreateWorkFlow(ctx context.Context, workFlow ArgoWor
92109
}
93110

94111
// mainly for update status
95-
func (s *ArgoWorkFlowStore) UpdateWorkFlow(ctx context.Context, workFlow ArgoWorkflow) (*ArgoWorkflow, error) {
112+
func (s *argoWorkFlowStoreImpl) UpdateWorkFlow(ctx context.Context, workFlow ArgoWorkflow) (*ArgoWorkflow, error) {
96113
_, err := s.db.Core.NewUpdate().Model(&workFlow).WherePK().Exec(ctx)
97114
return &workFlow, err
98115
}
99116

100117
// delete workflow by id
101-
func (s *ArgoWorkFlowStore) DeleteWorkFlow(ctx context.Context, id int64) error {
118+
func (s *argoWorkFlowStoreImpl) DeleteWorkFlow(ctx context.Context, id int64) error {
102119
_, err := s.db.Core.NewDelete().Model(&ArgoWorkflow{}).Where("id = ?", id).Exec(ctx)
103120
return err
104121
}

component/tag.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
type TagComponent interface {
18+
AllTagsByScopeAndCategory(ctx context.Context, scope string, category string) ([]*database.Tag, error)
1819
AllTags(ctx context.Context) ([]database.Tag, error)
1920
ClearMetaTags(ctx context.Context, repoType types.RepositoryType, namespace, name string) error
2021
UpdateMetaTags(ctx context.Context, tagScope database.TagScope, namespace, name, content string) ([]*database.RepositoryTag, error)

component/user.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type UserComponent interface {
3838
ListServerless(ctx context.Context, req types.DeployReq) ([]types.DeployRepo, int, error)
3939
GetUserByName(ctx context.Context, userName string) (*database.User, error)
4040
Prompts(ctx context.Context, req *types.UserPromptsReq) ([]types.PromptRes, int, error)
41+
Evaluations(ctx context.Context, req *types.UserEvaluationReq) ([]types.ArgoWorkFlowRes, int, error)
4142
}
4243

4344
func NewUserComponent(config *config.Config) (UserComponent, error) {
@@ -98,7 +99,7 @@ type userComponentImpl struct {
9899
// srs database.SpaceResourceStore
99100
// urs *database.UserResourcesStore
100101
promptStore database.PromptStore
101-
wfs *database.ArgoWorkFlowStore
102+
wfs database.ArgoWorkFlowStore
102103
}
103104

104105
func (c *userComponentImpl) Datasets(ctx context.Context, req *types.UserDatasetsReq) ([]types.Dataset, int, error) {

runner/component/workflow.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ type WorkFlowComponent interface {
4545
DeleteWorkflowInargo(ctx context.Context, delete *v1alpha1.Workflow) error
4646
FindWorkFlowById(ctx context.Context, id int64) (database.ArgoWorkflow, error)
4747
RunWorkflowsInformer(clusterPool *cluster.ClusterPool, config *config.Config)
48-
StartAcctRequestFee(wf database.ArgoWorkflow)
4948
}
5049

5150
func NewWorkFlowComponent(config *config.Config, clusterPool *cluster.ClusterPool) WorkFlowComponent {

runner/handler/workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type ArgoHandler struct {
1919
workflowNameSpace string
2020
modelDockerRegBase string
2121
config *config.Config
22-
wfc *component.WorkFlowComponent
22+
wfc component.WorkFlowComponent
2323
}
2424

2525
func NewArgoHandler(config *config.Config, clusterPool *cluster.ClusterPool) (*ArgoHandler, error) {

0 commit comments

Comments
 (0)