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,51 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/job/main/videoup-report/conf:go_default_library",
"//app/job/main/videoup-report/model/task:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"weightlog.go",
],
importpath = "go-common/app/job/main/videoup-report/dao/hbase",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/main/videoup-report/conf:go_default_library",
"//app/job/main/videoup-report/model/task:go_default_library",
"//library/database/hbase.v2: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,25 @@
package hbase
import (
"go-common/app/job/main/videoup-report/conf"
"go-common/library/database/hbase.v2"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
hbase *hbase.Client
}
// New new a archive dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
hbase: hbase.NewClient(&c.Hbase.Config),
}
return d
}
// Close fn
func (d *Dao) Close() {
}

View File

@@ -0,0 +1,31 @@
package hbase
import (
"context"
"flag"
"path/filepath"
"testing"
"go-common/app/job/main/videoup-report/conf"
"go-common/app/job/main/videoup-report/model/task"
. "github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func init() {
dir, _ := filepath.Abs("../../cmd/videoup-report-job.toml")
flag.Set("conf", dir)
conf.Init()
d = New(conf.Conf)
}
func Test_AddLog(t *testing.T) {
Convey("AddLog", t, func() {
err := d.AddLog(context.TODO(), &task.WeightLog{TaskID: 44441})
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,51 @@
package hbase
import (
"context"
"crypto/md5"
"encoding/binary"
"encoding/json"
"fmt"
"strconv"
"time"
"go-common/app/job/main/videoup-report/model/task"
"go-common/library/log"
)
var (
tableInfo = "ugc:ArchiveTaskWeight"
family = "weightlog"
)
// hashRowKey create rowkey(md5(tid)[:2]+tid) for track by tid.
func hashRowKey(tid int64) string {
var bs = make([]byte, 8)
binary.LittleEndian.PutUint64(bs, uint64(tid))
rk := md5.Sum(bs)
return fmt.Sprintf("%x%d", rk[:2], tid)
}
// AddLog task weight log.
func (d *Dao) AddLog(c context.Context, alog *task.WeightLog) (err error) {
var (
value []byte
fvalues = make(map[string][]byte)
column string
key = hashRowKey(alog.TaskID)
)
column = strconv.FormatInt(int64(alog.Uptime.TimeValue().Unix()), 10)
if value, err = json.Marshal(alog); err != nil {
log.Error("json.Marshal(%v) error(%v)", value, err)
return
}
fvalues[column] = value
values := map[string]map[string][]byte{family: fvalues}
ctx, cancel := context.WithTimeout(c, time.Duration(d.c.Hbase.WriteTimeout))
defer cancel()
// hbase info
if _, err = d.hbase.PutStr(ctx, tableInfo, key, values); err != nil {
log.Error("d.hbase.PutStr(%s,%s,%+v) error(%v)", tableInfo, key, values, err)
}
return
}