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,43 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = ["passport-game-data-job.toml"],
importpath = "go-common/app/job/main/passport-game-data/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/main/passport-game-data/conf:go_default_library",
"//app/job/main/passport-game-data/http:go_default_library",
"//app/job/main/passport-game-data/service:go_default_library",
"//library/log:go_default_library",
"//library/net/trace: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,97 @@
package main
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/job/main/passport-game-data/conf"
"go-common/app/job/main/passport-game-data/http"
"go-common/app/job/main/passport-game-data/service"
"go-common/library/log"
"go-common/library/net/trace"
)
var (
mode int
compareMidListFile string
diffLogFile string
diffParseResFile string
)
const (
_modeNormal = 0
_modeCompareOnly = 1
_modeParseDiffLog = 2
_modeInitCloud = 3
)
func init() {
flag.IntVar(&mode, "mode", _modeNormal, "mode for starting this job, 0 for normal, 1 for compare only, 2 for parse diff log")
flag.StringVar(&compareMidListFile, "compare_mid_list_file", "/tmp/mids.txt", "compare mid list file path")
flag.StringVar(&diffLogFile, "diff_log_file", "/tmp/diff.txt", "diff log file path")
flag.StringVar(&diffParseResFile, "diff_parse_res_file", "/tmp/diff_parse_res.txt", "diff parse result file path")
}
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Xlog)
defer log.Close()
trace.Init(conf.Conf.Tracer)
defer trace.Close()
var srv *service.Service
switch mode {
case _modeCompareOnly:
s := service.NewCompareOnly(conf.Conf)
if err := s.CompareFromMidListFile(context.TODO(), compareMidListFile); err != nil {
log.Error("service.CompareFromMidListFile(%s) error(%v)", compareMidListFile, err)
}
case _modeParseDiffLog:
log.Info("parse diff log from %s", diffLogFile)
if err := service.ParseDiffLog(diffLogFile, diffParseResFile); err != nil {
log.Error("service.ParseDiffLog(%s) error(%v)", diffLogFile, err)
}
time.Sleep(time.Second * 2)
return
case _modeInitCloud:
s := service.NewInitCloud(conf.Conf)
s.InitCloud(context.TODO())
time.Sleep(time.Second * 2)
case _modeNormal:
// service init
srv = service.New(conf.Conf)
http.Init(conf.Conf, srv)
// signal handler
log.Info("passport-game-data-job start")
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("passport-game-data-job get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
if srv != nil {
srv.Close()
}
log.Info("passport-game-data-job exit")
return
case syscall.SIGHUP:
// TODO reload
default:
return
}
}
}

View File

@@ -0,0 +1,84 @@
# This is a TOML document. Boom.
[compare]
# NOTE:
# startTime the mtime for compareproc to check from
# endTime the mtime for compareproc to check to
# stepDuration the duration step of compareproc to increase mtime,
# need to be greater than zero,
# the default value is 15m.
# loopDuration the duration between two adjacent loops of compareproc,
# need to be greater than or equal to zero,
# the default value is 3s.
# batchSize the batch size of selecting aso accounts from local aso_account table,
# the default value is 1000.
# batchMissRetryCount batch miss retry count of retrive aso accounts from local aso_account table,
# the default value is 3.
# debug if show debug messages,
# if switch this to on, will log additional compareproc info,
# such as the start time and end time of every loop.
[compare.cloud2Local]
on = false
offsetFilePath = "/data/passport-game-data-job.c2l.offset"
useOldOffset = true
end = true
startTime = "2017-11-15 22:24:45"
endTime = "2018-01-25 12:00:00"
delayDuration="15m"
stepDuration = "10m"
loopDuration = "1s"
batchSize = 1001
batchMissRetryCount = 4
fix = true
[compare.Local2Cloud]
on = true
offsetFilePath = "/data/passport-game-data-job.l2c.offset"
useOldOffset = false
end = true
startTime = "2018-02-06 11:36:09"
endTime = "2018-02-06 12:00:00"
delayDuration="10m"
stepDuration = "10m"
loopDuration = "1s"
batchSize = 1001
batchMissRetryCount = 4
fix = true
[db]
[db.local]
addr = "172.16.33.205:3306"
dsn = "aso:hA0DAnENNFz78kYB@tcp(172.16.33.205:3306)/aso?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 2
queryTimeout = "1s"
execTimeout = "2s"
tranTimeout = "2s"
[db.local.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.cloud]
addr = "172.16.33.205:3306"
dsn = "account:wx2U1MwXRyWEuURw@tcp(172.16.33.205:3306)/member_app1?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 2
queryTimeout = "1s"
execTimeout = "2s"
tranTimeout = "2s"
[db.cloud.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
go run main.go -conf ./passport-game-data-job-init-cloud.toml -mode 3