From 65e80fc73732a519f4bb8e816bf848fed7e32496 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 3 Feb 2023 10:25:17 +0800 Subject: [PATCH] [add] migrate task & schedule --- Makefile | 2 +- flow/flow_test.go | 8 -------- schedule/schedule.go | 3 +++ schedule/schedule_test.go | 15 +++++++++++++-- task/task.go | 22 +++------------------- task/task_test.go | 10 +++++++++- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 66f69076..dcec010b 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}') NOW := $(shell date +"%FT%T%z") # ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) -TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto' | grep -vE 'examples|tests*|config|widgets') +TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule' | grep -vE 'examples|tests*|config|widgets') TESTTAGS ?= "" # TESTWIDGETS := $(shell $(GO) list ./widgets/...) diff --git a/flow/flow_test.go b/flow/flow_test.go index 6922d7a7..48195010 100644 --- a/flow/flow_test.go +++ b/flow/flow_test.go @@ -24,12 +24,4 @@ func check(t *testing.T) { } assert.True(t, ids["tests.basic"]) assert.True(t, ids["tests.session"]) - - // wskeys := []string{} - // for key := range websocket.Upgraders { - // wskeys = append(wskeys, key) - // } - - // assert.Equal(t, 5, len(keys)) - // assert.Equal(t, 1, len(wskeys)) } diff --git a/schedule/schedule.go b/schedule/schedule.go index 91a55861..5ef28cab 100644 --- a/schedule/schedule.go +++ b/schedule/schedule.go @@ -11,6 +11,9 @@ import ( func Load(cfg config.Config) error { exts := []string{"*.sch.yao", "*.sch.json", "*.sch.jsonc"} return application.App.Walk("schedules", func(root, file string, isdir bool) error { + if isdir { + return nil + } _, err := schedule.Load(file, share.ID(root, file)) return err }, exts...) diff --git a/schedule/schedule_test.go b/schedule/schedule_test.go index bd29dcfd..af0fbd0d 100644 --- a/schedule/schedule_test.go +++ b/schedule/schedule_test.go @@ -7,14 +7,25 @@ import ( "github.com/yaoapp/gou/schedule" "github.com/yaoapp/yao/config" "github.com/yaoapp/yao/task" + "github.com/yaoapp/yao/test" ) func TestLoad(t *testing.T) { - task.Load(config.Conf) + test.Prepare(t, config.Conf) + defer test.Clean() + err := task.Load(config.Conf) + if err != nil { + t.Fatal(err) + } Load(config.Conf) check(t) } func check(t *testing.T) { - assert.Equal(t, 2, len(schedule.Schedules)) + ids := map[string]bool{} + for id := range schedule.Schedules { + ids[id] = true + } + assert.True(t, ids["mail"]) + assert.True(t, ids["sendmail"]) } diff --git a/task/task.go b/task/task.go index 10648319..53c12fae 100644 --- a/task/task.go +++ b/task/task.go @@ -11,26 +11,10 @@ import ( func Load(cfg config.Config) error { exts := []string{"*.yao", "*.json", "*.jsonc"} return application.App.Walk("tasks", func(root, file string, isdir bool) error { + if isdir { + return nil + } _, err := task.Load(file, share.ID(root, file)) return err }, exts...) } - -// // LoadFrom load from dir -// func LoadFrom(dir string, prefix string) error { - -// if share.DirNotExists(dir) { -// return fmt.Errorf("%s does not exists", dir) -// } - -// err := share.Walk(dir, ".json", func(root, filename string) { -// name := prefix + share.SpecName(root, filename) -// content := share.ReadFile(filename) -// _, err := gou.LoadTask(string(content), name) -// if err != nil { -// log.With(log.F{"root": root, "file": filename}).Error(err.Error()) -// } -// }) - -// return err -// } diff --git a/task/task_test.go b/task/task_test.go index e1e9781d..1cb0cc16 100644 --- a/task/task_test.go +++ b/task/task_test.go @@ -6,13 +6,21 @@ import ( "github.com/stretchr/testify/assert" "github.com/yaoapp/gou/task" "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/test" ) func TestLoad(t *testing.T) { + test.Prepare(t, config.Conf) + defer test.Clean() + Load(config.Conf) check(t) } func check(t *testing.T) { - assert.Equal(t, 1, len(task.Tasks)) + ids := map[string]bool{} + for id := range task.Tasks { + ids[id] = true + } + assert.True(t, ids["mail"]) }