Skip to content

Commit

Permalink
feat: 新增树状模版任务引擎模式
Browse files Browse the repository at this point in the history
  • Loading branch information
googs1025 committed Jan 6, 2024
1 parent f87a28a commit c725359
Show file tree
Hide file tree
Showing 46 changed files with 305 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- name: Run unit test
run: go test -v ./...
- name: Run unit tree-template-engine
run: go tree-template-engine -v ./...
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
bin
testbin/*

# Test binary, build with `go test -c`
# Test binary, build with `go tree-template-engine -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
Expand Down
4 changes: 3 additions & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@

22. event模式 [代码示例](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/event-mode)

23. worker-job模式 [代码示例](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/worker-job-mode)
23. worker-job模式 [代码示例](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/worker-job-mode)

24. tree-template-engine模式 [代码示例](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/tree-template-engine)
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ Concurrency modes that I usually learn (the mode classification is mainly based

22. event mode [code example](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/event-mode)

23. worker-job mode [code example](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/worker-job-mode)
23. worker-job mode [code example](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/worker-job-mode)

24. tree-template-engine mode [code example](https://github.com/StudyPlace-io/Golang-Concurrency-Pattern-Demo/tree/main/tree-template-engine)
2 changes: 1 addition & 1 deletion cron-task-mode/cronfunc/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func CronTry() {
}()
CronUntil(func() {
time.Sleep(100 * time.Millisecond)
log.Println("test")
log.Println("tree-template-engine")
}, 100*time.Millisecond, ch)
log.Println("main exit")
}
Expand Down
2 changes: 1 addition & 1 deletion event-mode/broadcaster/broadcaseter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package broadcaster

import (
"github.com/practice/Golang-Concurrency-Pattern-Demo/event-mode/event"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/event-mode/event"
"sync"
)

Expand Down
2 changes: 1 addition & 1 deletion event-mode/broadcaster/watcher.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package broadcaster

import (
"github.com/practice/Golang-Concurrency-Pattern-Demo/event-mode/event"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/event-mode/event"
)

// Interface 接口 watcher 实现
Expand Down
4 changes: 2 additions & 2 deletions event-mode/event_broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package event_broadcaster

import (
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/event-mode/broadcaster"
"github.com/practice/Golang-Concurrency-Pattern-Demo/event-mode/event"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/event-mode/broadcaster"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/event-mode/event"
"time"
)

Expand Down
12 changes: 6 additions & 6 deletions event-mode/event_broadcaster_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package event_broadcaster

import (
"github.com/practice/Golang-Concurrency-Pattern-Demo/event-mode/event"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/event-mode/event"
"testing"
"time"
)
Expand All @@ -13,16 +13,16 @@ func TestEventBroadcaster(t *testing.T) {

go func() {
time.Sleep(time.Second * 3)
eventBroadcast.Event(event.Warning, "test", "other-goroutine")
eventBroadcast.Event(event.Warning, "tree-template-engine", "other-goroutine")
time.Sleep(time.Second * 3)
eventBroadcast.EventBySource(event.Normal, "test", "other-goroutine", "api-server")
eventBroadcast.EventBySource(event.Normal, "tree-template-engine", "other-goroutine", "api-server")
time.Sleep(time.Second * 3)
eventBroadcast.Event(event.Normal, "test", "other-goroutine")
eventBroadcast.Event(event.Normal, "tree-template-engine", "other-goroutine")
}()

time.Sleep(time.Second * 3)
eventBroadcast.Event(event.Normal, "test", "main-goroutine")
eventBroadcast.EventBySource(event.Normal, "test", "main-goroutine", "api-server")
eventBroadcast.Event(event.Normal, "tree-template-engine", "main-goroutine")
eventBroadcast.EventBySource(event.Normal, "tree-template-engine", "main-goroutine", "api-server")

<-time.After(time.Second * 20)
eventBroadcast.Stop()
Expand Down
8 changes: 4 additions & 4 deletions exit-gracefully-mode/exit_gracefully1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"flag"
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/exit-gracefully-mode/signals"
"github.com/spf13/pflag"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/exit-gracefully-mode/signals"
"k8s.io/klog/v2"
"log"
"net/http"
Expand All @@ -28,7 +28,7 @@ func NewOptions() *Options {
}

const (
DefaultTest = "test"
DefaultTest = "tree-template-engine"
DefaultPort = 8080
DefaultHealthPort = 9999
)
Expand All @@ -37,7 +37,7 @@ const (
func (o *Options) AddFlags(flags *pflag.FlagSet) {
flags.IntVar(&o.Port, "port", DefaultPort, "xxx")
flags.IntVar(&o.Port, "healthPort", DefaultHealthPort, "xxx")
flags.StringVar(&o.test, "test", DefaultTest, "xxx")
flags.StringVar(&o.test, "tree-template-engine", DefaultTest, "xxx")
flags.IntVar(&o.test2, "test2", 1000, "xxx")
flags.BoolVar(&o.test1, "test1", false, "xxx")

Expand All @@ -56,7 +56,7 @@ func (o *Options) addKlogFlags(flags *pflag.FlagSet) {
}

func test(w http.ResponseWriter, req *http.Request) {
fmt.Println("test server")
fmt.Println("tree-template-engine server")
}

// Run 执行
Expand Down
6 changes: 3 additions & 3 deletions forever-mode/forever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestRunForever(t *testing.T) {
go func() {
RunForever(time.Second*5, func() error {
fmt.Println("test")
fmt.Println("tree-template-engine")
return nil
})
}()
Expand All @@ -28,7 +28,7 @@ func TestRunWithChannel(t *testing.T) {
}()

RunWithChannel(time.Second*5, func() error {
fmt.Println("test-channel")
fmt.Println("tree-template-engine-channel")
return nil
}, stopC)

Expand All @@ -40,7 +40,7 @@ func TestRunWithContext(t *testing.T) {
cancel()
}()
RunWithContext(time.Second*5, func() error {
fmt.Println("test-context")
fmt.Println("tree-template-engine-context")
return nil
}, ctx)
}
6 changes: 3 additions & 3 deletions forever-mode/forever_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestRunWithTimeForever(t *testing.T) {
go func() {
RunForeverWithTime(time.Second*1, func() error {
fmt.Println("test-forever-with-time")
fmt.Println("tree-template-engine-forever-with-time")
return nil
}, 3)
}()
Expand All @@ -28,7 +28,7 @@ func TestRunWithTimeWithChannel(t *testing.T) {
}()

RunWithTimeWithChannel(time.Second*2, func() error {
fmt.Println("test-with-time-channel")
fmt.Println("tree-template-engine-with-time-channel")
return nil
}, stopC, 5)

Expand All @@ -40,7 +40,7 @@ func TestRunWithTimeWithContext(t *testing.T) {
cancel()
}()
RunWithTimeWithContext(time.Second*1, func() error {
fmt.Println("test-with-time-context")
fmt.Println("tree-template-engine-with-time-context")
return nil
}, ctx, 10)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/practice/Golang-Concurrency-Pattern-Demo
module github.com/study-io/Golang-Concurrency-Pattern-Demo

go 1.18

require (
github.com/antlabs/timer v0.0.10
github.com/ghodss/yaml v1.0.0
github.com/google/uuid v1.3.0
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/goconvey v1.8.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 1 addition & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -356,8 +357,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.13.1 h1:Ef7KhSmjZcK6AVf9YbJdvPYG9avaF0ZxudX+ThRdWfU=
github.com/smartystreets/assertions v1.13.1/go.mod h1:cXr/IwVfSo/RbCSPhoAPv73p3hlSdrBH/b3SdnW/LMY=
Expand Down Expand Up @@ -560,7 +559,6 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
8 changes: 4 additions & 4 deletions gorountine-other-mode/group/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestGroup(t *testing.T) {

g.Start(func() {
time.Sleep(time.Second * 2)
fmt.Println("test")
fmt.Println("tree-template-engine")
})

g.Wait()
Expand All @@ -25,7 +25,7 @@ func TestGroupN(t *testing.T) {

g.StartN(5, func() {
time.Sleep(time.Second * 2)
fmt.Println("test")
fmt.Println("tree-template-engine")
})

g.Wait()
Expand All @@ -37,7 +37,7 @@ func TestGroupCtx(t *testing.T) {

g.StartWithContext(context.TODO(), func(ctx context.Context) {
time.Sleep(time.Second * 2)
fmt.Println("test")
fmt.Println("tree-template-engine")
})

g.Wait()
Expand All @@ -50,7 +50,7 @@ func TestGroupStopC(t *testing.T) {
stopC := make(chan struct{})
g.StartWithChannel(stopC, func(stopCh <-chan struct{}) {
time.Sleep(time.Second * 2)
fmt.Println("test")
fmt.Println("tree-template-engine")
select {
case <-stopC:
return
Expand Down
4 changes: 2 additions & 2 deletions kube-controller-manager-mode/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package app
import (
"context"
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app/config"
"github.com/practice/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app/options"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app/config"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app/options"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/component-base/version/verflag"
"k8s.io/klog/v2"
Expand Down
4 changes: 2 additions & 2 deletions kube-controller-manager-mode/app/my_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app
import (
"context"
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/pkg/controller/mycontroller1"
"github.com/practice/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/pkg/controller/mycontroller2"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/pkg/controller/mycontroller1"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/pkg/controller/mycontroller2"
"k8s.io/klog/v2"
)

Expand Down
2 changes: 1 addition & 1 deletion kube-controller-manager-mode/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package options
import (
"flag"
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app/config"
"github.com/spf13/pflag"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app/config"
"k8s.io/klog/v2"
"os"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion kube-controller-manager-mode/controller-manager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/practice/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kube-controller-manager-mode/app"
"k8s.io/component-base/cli"
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
_ "k8s.io/component-base/metrics/prometheus/restclient"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mycontroller1
import (
"context"
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/gorountine-other-mode/group"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/gorountine-other-mode/group"
)

// Controller 控制器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mycontroller2
import (
"context"
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/gorountine-other-mode/group"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/gorountine-other-mode/group"
)

// Controller 控制器
Expand Down
2 changes: 1 addition & 1 deletion kube-controller-mode/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kube_controller_mode

import (
"fmt"
"github.com/practice/Golang-Concurrency-Pattern-Demo/gorountine-other-mode/group"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/gorountine-other-mode/group"
)

// Controller 控制器
Expand Down
2 changes: 1 addition & 1 deletion kubelet-podworker-mode/kubelet.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/practice/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/app"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/app"
"k8s.io/component-base/cli"
"os"
)
Expand Down
2 changes: 1 addition & 1 deletion kubelet-podworker-mode/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package kubelet

import (
"context"
"github.com/practice/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/config"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/config"
"k8s.io/klog/v2"
"time"
)
Expand Down
6 changes: 3 additions & 3 deletions kubelet-podworker-mode/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kubelet

import (
"github.com/practice/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/config"
"github.com/practice/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/container"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/config"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/container"
"testing"
"time"
)
Expand All @@ -11,7 +11,7 @@ func TestKubelet(t *testing.T) {

k := &Kubelet{
config: config.NewKubeletConfig(),
node: "test",
node: "tree-template-engine",
registerNode: true,
registerSchedulable: true,
podManager: NewBasicPodManager(),
Expand Down
2 changes: 1 addition & 1 deletion kubelet-podworker-mode/kubelet/pod.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kubelet

import (
"github.com/practice/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/container"
"github.com/study-io/Golang-Concurrency-Pattern-Demo/kubelet-podworker-mode/kubelet/container"
)

// Pod 模拟Pod对象
Expand Down
Loading

0 comments on commit c725359

Please sign in to comment.