-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Min Min <[email protected]>
- Loading branch information
Showing
8 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
pkg/microservice/aslan/core/common/repository/models/workflow_task_revert.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2025 The KodeRover Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package models | ||
|
||
import ( | ||
"github.com/koderover/zadig/v2/pkg/microservice/aslan/config" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
type WorkflowTaskRevert struct { | ||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` | ||
TaskID int64 `bson:"task_id" json:"task_id"` | ||
WorkflowName string `bson:"workflow_name" json:"workflow_name"` | ||
JobName string `bson:"job_name" json:"job_name"` | ||
RevertSpec interface{} `bson:"revert_spec" json:"revert_spec"` | ||
CreateTime int64 `bson:"create_time" json:"create_time,omitempty"` | ||
TaskCreator string `bson:"creator" json:"creator,omitempty"` | ||
TaskCreatorID string `bson:"creator_id" json:"creator_id,omitempty"` | ||
Status config.Status `bson:"status" json:"status,omitempty"` | ||
} | ||
|
||
func (WorkflowTaskRevert) TableName() string { | ||
return "workflow_task_revert" | ||
} |
83 changes: 83 additions & 0 deletions
83
pkg/microservice/aslan/core/common/repository/mongodb/workflow_task_revert.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright 2025 The KodeRover Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mongodb | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
|
||
"github.com/koderover/zadig/v2/pkg/microservice/aslan/config" | ||
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" | ||
mongotool "github.com/koderover/zadig/v2/pkg/tool/mongo" | ||
) | ||
|
||
type WorkflowTasKRevertColl struct { | ||
*mongo.Collection | ||
|
||
coll string | ||
} | ||
|
||
func NewWorkflowTaskRevertColl() *WorkflowTasKRevertColl { | ||
name := models.WorkflowTaskRevert{}.TableName() | ||
return &WorkflowTasKRevertColl{Collection: mongotool.Database(config.MongoDatabase()).Collection(name), coll: name} | ||
} | ||
|
||
func (c *WorkflowTasKRevertColl) GetCollectionName() string { | ||
return c.coll | ||
} | ||
|
||
func (c *WorkflowTasKRevertColl) EnsureIndex(ctx context.Context) error { | ||
mod := []mongo.IndexModel{ | ||
{ | ||
Keys: bson.D{ | ||
bson.E{Key: "workflow_name", Value: 1}, | ||
bson.E{Key: "task_id", Value: 1}, | ||
bson.E{Key: "job_name", Value: 1}, | ||
}, | ||
Options: options.Index().SetUnique(false), | ||
}, | ||
{ | ||
Keys: bson.M{"create_time": 1}, | ||
Options: options.Index().SetUnique(false), | ||
}, | ||
} | ||
|
||
_, err := c.Indexes().CreateMany(ctx, mod) | ||
|
||
return err | ||
} | ||
|
||
func (c *WorkflowTasKRevertColl) Create(obj *models.WorkflowTaskRevert) (string, error) { | ||
if obj == nil { | ||
return "", fmt.Errorf("nil object") | ||
} | ||
|
||
res, err := c.InsertOne(context.TODO(), obj) | ||
if err != nil { | ||
return "", err | ||
} | ||
ID, ok := res.InsertedID.(primitive.ObjectID) | ||
if !ok { | ||
return "", fmt.Errorf("failed to get object id from create") | ||
} | ||
return ID.Hex(), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters