Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["service_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/web-show/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"jobs.go",
"service.go",
],
importpath = "go-common/app/interface/main/web-show/service/job",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/web-show/conf:go_default_library",
"//app/interface/main/web-show/dao/job:go_default_library",
"//app/interface/main/web-show/model/job:go_default_library",
"//library/log:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,13 @@
package job
import (
"context"
jobmdl "go-common/app/interface/main/web-show/model/job"
)
// Jobs get job infos
func (s *Service) Jobs(c context.Context) (js []*jobmdl.Job) {
js = s.cache
return
}

View File

@@ -0,0 +1,75 @@
package job
import (
"context"
"time"
"go-common/app/interface/main/web-show/conf"
"go-common/app/interface/main/web-show/dao/job"
jobmdl "go-common/app/interface/main/web-show/model/job"
"go-common/library/log"
)
var (
_emptyJobs = make([]*jobmdl.Job, 0)
)
// Service struct
type Service struct {
dao *job.Dao
cache []*jobmdl.Job
}
// New init
func New(c *conf.Config) (s *Service) {
s = &Service{}
s.dao = job.New(c)
s.cache = _emptyJobs
s.reload()
go s.loadproc()
return
}
// jobproc load job infos to cache
func (s *Service) loadproc() {
for {
s.reload()
time.Sleep(time.Duration(conf.Conf.Reload.Jobs))
}
}
// reload
func (s *Service) reload() {
js, err := s.dao.Jobs(context.Background())
if err != nil {
log.Error("s.job.Jobs error(%v)", err)
return
} else if len(js) == 0 {
s.cache = _emptyJobs
}
cates, err := s.dao.Categories(context.Background())
if err != nil {
log.Error("job.Categories error(%v)", err)
return
}
cs := make(map[int]string, len(cates))
for _, cate := range cates {
cs[cate.ID] = cate.Name
}
for _, j := range js {
j.JobsCla = cs[j.CateID]
j.Location = cs[j.AddrID]
}
s.cache = js
}
// Ping Service
func (s *Service) Ping(c context.Context) (err error) {
err = s.dao.Ping(c)
return
}
// Close Service
func (s *Service) Close() {
s.dao.Close()
}

View File

@@ -0,0 +1,40 @@
package job
import (
"context"
"flag"
"path/filepath"
"testing"
"time"
"go-common/app/interface/main/web-show/conf"
. "github.com/smartystreets/goconvey/convey"
)
var svf *Service
func init() {
dir, _ := filepath.Abs("../../cmd/web-show-test.toml")
flag.Set("conf", dir)
if err := conf.Init(); err != nil {
panic(err)
}
if svf == nil {
svf = New(conf.Conf)
}
time.Sleep(time.Second)
}
func WithService(f func(s *Service)) func() {
return func() {
f(svf)
}
}
func TestService_Jobs(t *testing.T) {
Convey("should return without err", t, WithService(func(svf *Service) {
res := svf.Jobs(context.TODO())
So(res, ShouldNotBeNil)
Printf("%+v", res)
}))
}