当前位置: 首页>>代码示例>>Golang>>正文


Golang TaskStatus.Status方法代码示例

本文整理汇总了Golang中github.com/crunchydata/crunchy-postgresql-manager/task.TaskStatus.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang TaskStatus.Status方法的具体用法?Golang TaskStatus.Status怎么用?Golang TaskStatus.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/crunchydata/crunchy-postgresql-manager/task.TaskStatus的用法示例。


在下文中一共展示了TaskStatus.Status方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {

	fmt.Println("backupcommand running....")
	_, err := io.WriteString(file, "backupcommand running....\n")
	if err != nil {
		fmt.Println(err.Error())
	}

	defer closeLog()

	getEnvVars()
	s := task.TaskStatus{}
	eDuration := time.Since(startTime)
	s.StartTime = startTimeString
	//s.ElapsedTime = eDuration.String()
	s.ElapsedTime = fmt.Sprintf("%.3fs", eDuration.Seconds())
	s.Status = "initializing"
	s.TaskSize = du()
	sendStats(&s)

	//kick off stats reporting in a separate thread
	go stats("hi")

	fmt.Println("giving DNS time to register the backup job...sleeping for 7s")
	io.WriteString(file, "giving DNS time to register the backup job....sleeping for 7 secs")
	sleepTime, _ := time.ParseDuration("7s")
	time.Sleep(sleepTime)

	//perform the backup
	backupfunc("end")

	//send final stats to backup
	finalstats("end")

}
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:35,代码来源:backupcommand.go

示例2: sendStats

func sendStats(stats *task.TaskStatus) error {
	logit.Info.Println("restore - " + restoreBackupPath + " to " + restoreContainerName + " - " + stats.Status)

	stats.Status = "restore - " + restoreBackupPath + " to " + restoreContainerName + " - " + stats.Status
	stats.ContainerName = restoreContainerName
	stats.ScheduleID = restoreScheduleID
	stats.ProfileName = "restore"
	stats.Path = restoreContainerName
	stats.TaskName = restoreContainerName
	stats.ID = StatusID

	var addResponse task.StatusAddResponse
	var err error

	if StatusID != "" {
		_, err = task.StatusUpdateClient(stats)
	} else {
		addResponse, err = task.StatusAddClient(stats)
		StatusID = addResponse.ID
	}
	if err != nil {
		logit.Error.Println("error in adding status:" + err.Error())
		return err
	}

	return nil
}
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:27,代码来源:restorecommand.go

示例3: finalstats

//report stats back to the cpm-admin for this backup job
func finalstats(str string) {

	//connect to backupserver on cpm-admin
	//send stats to backup
	stats := task.TaskStatus{}
	eDuration := time.Since(startTime)
	stats.StartTime = startTimeString
	stats.ElapsedTime = eDuration.String()
	stats.Status = "completed"
	stats.TaskSize = "n/a"

	sendStats(&stats)
	logit.Info.Println("final stats here")
}
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:15,代码来源:backrestrestorecommand.go

示例4: stats

//report stats back to the cpm-admin for this job
func stats(str string) {

	sleepTime, _ := time.ParseDuration("7s")

	//logit.Info.Println("sending stats...")
	//logit.Info.Println("sleeping for 7 secs")
	time.Sleep(sleepTime)
	stats := task.TaskStatus{}
	eDuration := time.Since(startTime)
	stats.StartTime = startTimeString
	stats.ElapsedTime = eDuration.String()
	stats.Status = str
	stats.TaskSize = "n/a"
	sendStats(&stats)
}
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:16,代码来源:backrestrestorecommand.go

示例5: finalstats

//report stats back to the cpm-admin for this backup job
func finalstats(str string) {

	//connect to backupserver on cpm-admin
	//send stats to backup
	stats := task.TaskStatus{}
	eDuration := time.Since(startTime)
	stats.StartTime = startTimeString
	//stats.ElapsedTime = eDuration.String()
	stats.ElapsedTime = fmt.Sprintf("%.3fs", eDuration.Seconds())
	stats.Status = "completed"
	stats.TaskSize = du()

	sendStats(&stats)
	fmt.Println("final stats here")
	io.WriteString(file, "final stats here\n")
}
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:17,代码来源:backupcommand.go

示例6: stats

//report stats back to the cpm-admin for this backup job
func stats(str string) {

	sleepTime, _ := time.ParseDuration("7s")

	for true {
		fmt.Println("sending stats...")
		io.WriteString(file, "sending stats...\n")
		io.WriteString(file, "sleeping for 7 secs\n")
		time.Sleep(sleepTime)
		stats := task.TaskStatus{}
		eDuration := time.Since(startTime)
		stats.StartTime = startTimeString
		//stats.ElapsedTime = eDuration.String()
		stats.ElapsedTime = fmt.Sprintf("%.3fs", eDuration.Seconds())
		stats.Status = "running"
		stats.TaskSize = du()
		sendStats(&stats)
	}
}
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:20,代码来源:backupcommand.go

示例7: main

func main() {

	startTime = time.Now()
	startTimeString = startTime.String()
	logit.Info.Println("backrestrestore running....")

	err := getEnvVars()
	if err != nil {
		logit.Error.Println(err.Error())
		return
	}

	s := task.TaskStatus{}
	eDuration := time.Since(startTime)
	s.StartTime = startTimeString
	s.ElapsedTime = eDuration.String()
	s.Status = "initializing"
	s.TaskSize = "n/a"
	sendStats(&s)

	logit.Info.Println("giving DNS time to register the backup job....sleeping for 7 secs")
	sleepTime, _ := time.ParseDuration("7s")
	time.Sleep(sleepTime)

	stats("restore job starting")

	stats("stopping postgres...")
	var stopResponse cpmcontainerapi.StopPGResponse
	stopResponse, err = cpmcontainerapi.StopPGClient(restoreContainerName)
	if err != nil {
		logit.Error.Println(err.Error())
		s.Status = "error in stopPG"
		sendStats(&s)
		os.Exit(1)
	}
	logit.Info.Println("StopPG....")
	logit.Info.Println(stopResponse.Output)
	logit.Info.Println(stopResponse.Status)
	logit.Info.Println("End of StopPG....")

	//wait for postgres to quit
	time.Sleep(sleepTime)

	stats("performing the restore...")
	//perform the restore
	restoreRequest := cpmcontainerapi.RestoreRequest{}
	restoreRequest.RestoreRemotePath = restoreRemotePath
	restoreRequest.RestoreRemoteHost = restoreRemoteHost
	restoreRequest.RestoreRemoteUser = restoreRemoteUser
	restoreRequest.RestoreDbUser = restoreDbUser
	restoreRequest.RestoreDbPass = restoreDbPass
	restoreRequest.RestoreSet = restoreSet

	var restoreResponse cpmcontainerapi.RestoreResponse
	restoreResponse, err = cpmcontainerapi.RestoreClient(restoreContainerName, &restoreRequest)
	if err != nil {
		logit.Error.Println(err.Error())
		s.Status = "error in restore"
		sendStats(&s)
		os.Exit(1)
	}
	logit.Info.Println("Restore....")
	logit.Info.Println(restoreResponse.Output)
	logit.Info.Println(restoreResponse.Status)
	logit.Info.Println("End of Restore....")

	stats("starting postgres after the restore...")

	var startResponse cpmcontainerapi.StartPGResponse
	startResponse, err = cpmcontainerapi.StartPGClient(restoreContainerName)
	if err != nil {
		logit.Error.Println(err.Error())
		s.Status = "error in startPG"
		sendStats(&s)
		os.Exit(1)
	}
	logit.Info.Println("StartPG....")
	logit.Info.Println(startResponse.Output)
	logit.Info.Println(startResponse.Status)
	logit.Info.Println("End of StartPG....")

	stats("seeding the database...")
	var seedResponse cpmcontainerapi.SeedResponse
	seedResponse, err = cpmcontainerapi.SeedClient(restoreContainerName)
	if err != nil {
		logit.Error.Println(err.Error())
		s.Status = "error in Seed"
		sendStats(&s)
		os.Exit(1)
	}
	logit.Info.Println("Seed....")
	logit.Info.Println(seedResponse.Output)
	logit.Info.Println(seedResponse.Status)
	logit.Info.Println("End of Seed....")

	//send final stats to backup
	finalstats("restore completed")

}
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:99,代码来源:backrestrestorecommand.go

示例8: main

func main() {

	startTime = time.Now()
	startTimeString = startTime.String()
	logit.Info.Println("backrestrestore running....")

	err := getEnvVars()
	if err != nil {
		logit.Error.Println(err.Error())
		return
	}

	s := task.TaskStatus{}
	eDuration := time.Since(startTime)
	s.StartTime = startTimeString
	//s.ElapsedTime = eDuration.String()
	s.ElapsedTime = fmt.Sprintf("%.3fs", eDuration.Seconds())
	s.Status = "initializing"
	s.TaskSize = "n/a"
	sendStats(&s)

	//	logit.Info.Println("giving DNS time to register the backup job....sleeping for 7 secs")
	sleepTime, _ := time.ParseDuration("7s")
	//	time.Sleep(sleepTime)

	stats("restore job starting")

	stats("stopping postgres...")
	var stopResponse cpmcontainerapi.StopPGResponse
	stopResponse, err = cpmcontainerapi.StopPGClient(restoreContainerName)
	if err != nil {
		logit.Error.Println(err.Error())
		s.Status = "error in stopPG"
		sendStats(&s)
		os.Exit(1)
	}
	logit.Info.Println("StopPG....")
	logit.Info.Println(stopResponse.Output)
	logit.Info.Println(stopResponse.Status)
	logit.Info.Println("End of StopPG....")

	//wait for postgres to quit
	time.Sleep(sleepTime)

	stats("performing the restore...")
	//perform the restore
	//remove anything left in the /pgdata on the receiving container
	logit.Info.Println("removing any existing pgdata files")
	var frompath string
	frompath = "/pgdata/" + restorePath + "/*"
	logit.Info.Println("/bin/rm -rf " + frompath)
	var cmd *exec.Cmd
	cmd = exec.Command("/bin/rm", "-rf", frompath)
	var out bytes.Buffer
	var stderr bytes.Buffer
	cmd.Stdout = &out
	cmd.Stderr = &stderr
	err = cmd.Run()
	if err != nil {
		logit.Error.Println(err.Error())
		logit.Error.Println("rm stdout=" + out.String())
		logit.Error.Println("rm stderr=" + stderr.String())
		s.Status = "error in removing old files"
		sendStats(&s)
		os.Exit(1)
	}
	logit.Info.Println("remove was successful")

	//I'm choosing to do the remove here this way since this restore
	//might be a HUGE amount of data and the copy command could run a LONG
	//time, longer than an http timeout might allow for, since restorecommand
	//is running inside a container itself, this copy can run any amount of time

	//copy from the backup path all files to the /pgdata on the receiving container
	frompath = " /pgdata" + restoreBackupPath
	topath := "  /pgdata/" + restorePath
	logit.Info.Println("/var/cpm/bin/copyfiles.sh" + frompath + topath)
	cmd = exec.Command("/var/cpm/bin/copyfiles.sh", frompath, topath)
	cmd.Stdout = &out
	cmd.Stderr = &stderr
	err = cmd.Run()
	if err != nil {
		logit.Error.Println(err.Error())
		s.Status = "error in copying backup files"
		logit.Error.Println("cp stdout=" + out.String())
		logit.Error.Println("cp stderr=" + stderr.String())
		sendStats(&s)
		os.Exit(1)
	}

	logit.Info.Println("restore - copy of files was successful...")

	stats("starting postgres after the restore...")

	var startResponse cpmcontainerapi.StartPGResponse
	startResponse, err = cpmcontainerapi.StartPGClient(restoreContainerName)
	if err != nil {
		logit.Error.Println(err.Error())
		s.Status = "error in startPG"
		sendStats(&s)
//.........这里部分代码省略.........
开发者ID:rogervaas,项目名称:crunchy-postgresql-manager,代码行数:101,代码来源:restorecommand.go


注:本文中的github.com/crunchydata/crunchy-postgresql-manager/task.TaskStatus.Status方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。