添加obs命令

master
daiao 5 years ago
parent 4268d71896
commit 8820afe96b

@ -73,7 +73,7 @@ var uploadgitCmd = &cobra.Command{
go handler.Productor(ch, dbw)
wg.Add(wgNums)
for i := 0; i < ConsumerNum; i++ {
go handler.Consumer(ch, dbw, wg, ObjectStorgeLink)
go handler.Consumer(ch, dbw, wg, ObjectStorgeLink, obsCommand)
}
wg.Wait()
eT := time.Since(startT)

@ -33,6 +33,7 @@ var (
ChannelCap int // channel的容量大小
ConsumerNum int //comusers Numebr
SqlConnect string // mysql 链接方式
obsCommand string // obs 命令
)
@ -71,6 +72,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&SqlConnect, "sqlcon", "root:123456789@tcp(127.0.0.1:3306)/gitlab", "connect sql (default is $HOME/.objectss.yaml) ")
rootCmd.PersistentFlags().IntVarP(&ConsumerNum,"consusmerNum","s",100,"Run the number of comsumer goroutines (-s 100)")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.objectss.yaml) ")
rootCmd.PersistentFlags().StringVarP(&obsCommand, "obsCommand", "obscmd", "obsutil sync", "obs cmd (default is obsutil sync)")
rootCmd.PersistentFlags().IntVarP(&ChannelCap,"ChannelCap","c",10,"channle cap (-c 10)")
// Cobra also supports local flags, which will only ru

@ -21,12 +21,7 @@ func Productor(channel chan string, dbw *database.DbWorker) {
}
// 消费者负责执行shell
func Consumer(channel chan string, dbw *database.DbWorker, wg *sync.WaitGroup, osslink string) {
//errOut :=*utils.Log
//logfile,_:=os.OpenFile("logs/objectss_err.log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
//errOut.SetOutput(logfile)
func Consumer(channel chan string, dbw *database.DbWorker, wg *sync.WaitGroup, osslink string, obsCommand string) {
for {
path, ok := <-channel // 此处会阻塞, 如果信道中没有数据的话
if ok {
@ -36,7 +31,7 @@ func Consumer(channel chan string, dbw *database.DbWorker, wg *sync.WaitGroup, o
//utils.Log.Info("path:", pathDir, "ComsumerNume:", ComsuNum)
// 拷贝版本库到oss
ossPath := fmt.Sprintf("%s%s", osslink, path)
copyExec := fmt.Sprintf("obsutil sync %s %s", path, ossPath)
copyExec := fmt.Sprintf("%s %s %s", obsCommand, path, ossPath)
fmt.Println("shell:", copyExec)
s, err := Exec_linux_shell(copyExec)
@ -44,6 +39,7 @@ func Consumer(channel chan string, dbw *database.DbWorker, wg *sync.WaitGroup, o
if err == nil {
dbw.UpdateRepositoryOssbyPath(path)
} else {
utils.Log.Errorf("对象存储命令行执行失败,错误为: %s ; 执行命令为: %s ; 命令返回值: %s ",err,copyExec,s )
}

Loading…
Cancel
Save