Skip to content

Commit

Permalink
feat: api/config.ts文件冲突问题 --story=115998324
Browse files Browse the repository at this point in the history
  • Loading branch information
q15971095971 committed Aug 23, 2024
2 parents 4dc8ffe + e0c6f87 commit 35a5ad5
Show file tree
Hide file tree
Showing 379 changed files with 52,924 additions and 47,391 deletions.
44 changes: 44 additions & 0 deletions bcs-common/common/task/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* 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 task

import (
"fmt"

"github.com/Tencent/bk-bcs/bcs-common/common/task/types"
)

// NewByTaskBuilder init task from builder
func NewByTaskBuilder(builder types.TaskBuilder, opts ...types.TaskOption) (*types.Task, error) {
// 声明step
steps, err := builder.Steps()
if err != nil {
return nil, err
}

if len(steps) == 0 {
return nil, fmt.Errorf("task steps empty")
}

task := types.NewTask(builder.TaskInfo(), opts...)
task.Steps = steps
task.CurrentStep = steps[0].GetName()

// 自定义extraJson等
newTask, err := builder.BuildTask(*task)
if err != nil {
return nil, err
}

return &newTask, nil
}
15 changes: 7 additions & 8 deletions bcs-common/common/task/example/call_back.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package main
import (
"fmt"

"github.com/Tencent/bk-bcs/bcs-common/common/task/types"
istep "github.com/Tencent/bk-bcs/bcs-common/common/task/steps/iface"
)

const (
Expand All @@ -25,17 +25,16 @@ const (

type callBack struct{}

// GetName 回调方法名称
func (c *callBack) GetName() string {
return callBackName
}

// Callback 回调方法,根据任务成功状态更新实体对象状态
func (c *callBack) Callback(isSuccess bool, task *types.Task) {
if isSuccess {
func (cb *callBack) Callback(c *istep.Context, cbErr error) {
if cbErr != nil {
fmt.Println("success")
return
}

fmt.Println("failure")
}

func init() {
istep.RegisterCallback(istep.CallbackName(callBackName), &callBack{})
}
6 changes: 3 additions & 3 deletions bcs-common/common/task/example/example_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (

var (
// ExampleTask task
ExampleTask istep.TaskName = "测试任务"
ExampleTask types.TaskName = "测试任务"
// TestTask task for test
TestTask istep.TaskType = "TestTask"
TestTask types.TaskType = "TestTask"
)

// NewExampleTask build example task
Expand Down Expand Up @@ -79,7 +79,7 @@ func (st *Example) Steps() []*types.Step {
}

// BuildTask build task
func (st *Example) BuildTask(info *types.TaskInfo, opts ...types.TaskOption) (*types.Task, error) {
func (st *Example) BuildTask(info types.TaskInfo, opts ...types.TaskOption) (*types.Task, error) {
t := types.NewTask(info, opts...)
if len(st.Steps()) == 0 {
return nil, fmt.Errorf("task steps empty")
Expand Down
9 changes: 4 additions & 5 deletions bcs-common/common/task/example/hello_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"context"
"fmt"

istep "github.com/Tencent/bk-bcs/bcs-common/common/task/steps/iface"
Expand Down Expand Up @@ -44,15 +43,15 @@ func (s HelloStep) GetName() string {
return method
}

// DoWork for worker exec task
func (s HelloStep) DoWork(ctx context.Context, step *istep.Work) error {
fmt.Printf("%s %s %s\n", step.GetTaskID(), step.GetTaskType(), step.GetTaskName())
// Execute for worker exec task
func (s HelloStep) Execute(c *istep.Context) error {
fmt.Printf("%s %s %s\n", c.GetTaskID(), c.GetTaskType(), c.GetTaskName())
return nil
}

// BuildStep build step
func (s HelloStep) BuildStep(kvs []istep.KeyValue, opts ...types.StepOption) *types.Step {
step := types.NewStep(s.GetName(), s.Alias(), opts...)
step := types.NewStep(s.GetName(), method, opts...)

// build step paras
for _, v := range kvs {
Expand Down
20 changes: 4 additions & 16 deletions bcs-common/common/task/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ var (
// nolint
func main() {
pwd := os.Getenv("MONGO_PASSWORD")
if pwd == "" {
pwd = "12345"
}

mongoOpts := &bcsmongo.Options{
Hosts: mongoHosts,
Expand Down Expand Up @@ -124,8 +121,6 @@ func main() {
Lock: lock,
Store: store,
}
// register step worker && callback
config.CallBacks = registerCallbacks()

// init task manager
err = btm.Init(config)
Expand All @@ -144,14 +139,14 @@ func main() {
// build tak && run
sum := NewExampleTask("3", "5")

info := &types.TaskInfo{
info := types.TaskInfo{
TaskIndex: "example",
TaskType: "example-test",
TaskName: "example",
Creator: "bcs",
}
sumTask, err := sum.BuildTask(info, types.WithTaskMaxExecutionSeconds(0),
types.WithTaskCallBackFunc(callBackName))
types.WithTaskCallback(callBackName))
if err != nil {
fmt.Println(err)
return
Expand All @@ -173,8 +168,8 @@ func main() {
}

// nolint
func registerSteps() []istep.StepWorkerInterface {
steps := make([]istep.StepWorkerInterface, 0)
func registerSteps() []istep.StepExecutor {
steps := make([]istep.StepExecutor, 0)

sum := NewSumStep()
steps = append(steps, sum)
Expand All @@ -184,10 +179,3 @@ func registerSteps() []istep.StepWorkerInterface {

return steps
}

func registerCallbacks() []istep.CallbackInterface {
callbacks := make([]istep.CallbackInterface, 0)
callbacks = append(callbacks, &callBack{})

return callbacks
}
17 changes: 8 additions & 9 deletions bcs-common/common/task/example/sum_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"context"
"fmt"
"strconv"

Expand Down Expand Up @@ -51,25 +50,25 @@ func (s SumStep) GetName() string {
return sumMethod
}

// DoWork for worker exec task
func (s SumStep) DoWork(ctx context.Context, step *istep.Work) error {
a, _ := step.GetParam(sumA.String())
b, _ := step.GetParam(sumB.String())
// Execute for worker exec task
func (s SumStep) Execute(c *istep.Context) error {
a, _ := c.GetParam(sumA.String())
b, _ := c.GetParam(sumB.String())

a1, _ := strconv.Atoi(a)
b1, _ := strconv.Atoi(b)

c := a1 + b1
_ = step.AddCommonParams(sumC.String(), fmt.Sprintf("%v", c))
c1 := a1 + b1
_ = c.AddCommonParam(sumC.String(), fmt.Sprintf("%v", c1))

fmt.Printf("%s %s %s sumC: %v\n", step.GetTaskID(), step.GetTaskType(), step.GetName(), c)
fmt.Printf("%s %s %s sumC: %v\n", c.GetTaskID(), c.GetTaskType(), c.GetName(), c)

return nil
}

// BuildStep build step
func (s SumStep) BuildStep(kvs []istep.KeyValue, opts ...types.StepOption) *types.Step {
step := types.NewStep(s.GetName(), s.Alias(), opts...)
step := types.NewStep(s.GetName(), sumMethod, opts...)

// build step paras
for _, v := range kvs {
Expand Down
Loading

0 comments on commit 35a5ad5

Please sign in to comment.