[add] migrate task & schedule
This commit is contained in:
parent
c3e74b7964
commit
65e80fc737
6 changed files with 29 additions and 31 deletions
2
Makefile
2
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/...)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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...)
|
||||
|
|
|
|||
|
|
@ -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"])
|
||||
}
|
||||
|
|
|
|||
22
task/task.go
22
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
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -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"])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue