本文整理匯總了Golang中github.com/catalyzeio/cli/lib/jobs.IJobs.PollTillFinished方法的典型用法代碼示例。如果您正苦於以下問題:Golang IJobs.PollTillFinished方法的具體用法?Golang IJobs.PollTillFinished怎麽用?Golang IJobs.PollTillFinished使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/catalyzeio/cli/lib/jobs.IJobs
的用法示例。
在下文中一共展示了IJobs.PollTillFinished方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CmdBackup
func CmdBackup(databaseName string, skipPoll bool, id IDb, is services.IServices, ij jobs.IJobs) error {
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
job, err := id.Backup(service)
if err != nil {
return err
}
logrus.Printf("Backup started (job ID = %s)", job.ID)
if !skipPoll {
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte("Polling until backup finishes."))
status, err := ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nEnded in status '%s'", job.Status)
err = id.DumpLogs("backup", job, service)
if err != nil {
return err
}
if job.Status != "finished" {
return fmt.Errorf("Job finished with invalid status %s", job.Status)
}
}
logrus.Printf("You can download your backup with the \"catalyze db download %s %s ./output_file_path\" command", databaseName, job.ID)
return nil
}
示例2: CmdImport
func CmdImport(databaseName, filePath, mongoCollection, mongoDatabase string, id IDb, is services.IServices, ij jobs.IJobs) error {
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return fmt.Errorf("A file does not exist at path '%s'", filePath)
}
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
logrus.Printf("Backing up \"%s\" before performing the import", databaseName)
job, err := id.Backup(service)
if err != nil {
return err
}
logrus.Printf("Backup started (job ID = %s)", job.ID)
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte("Polling until backup finishes."))
status, err := ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nEnded in status '%s'", job.Status)
err = id.DumpLogs("backup", job, service)
if err != nil {
return err
}
if job.Status != "finished" {
return fmt.Errorf("Job finished with invalid status %s", job.Status)
}
logrus.Printf("Importing '%s' into %s (ID = %s)", filePath, databaseName, service.ID)
job, err = id.Import(filePath, mongoCollection, mongoDatabase, service)
if err != nil {
return err
}
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte(fmt.Sprintf("Processing import (job ID = %s).", job.ID)))
status, err = ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nImport complete (end status = '%s')", job.Status)
err = id.DumpLogs("restore", job, service)
if err != nil {
return err
}
if job.Status != "finished" {
return fmt.Errorf("Finished with invalid status %s", job.Status)
}
return nil
}
示例3: CmdExport
func CmdExport(databaseName, filePath string, force bool, id IDb, ip prompts.IPrompts, is services.IServices, ij jobs.IJobs) error {
err := ip.PHI()
if err != nil {
return err
}
if !force {
if _, err := os.Stat(filePath); err == nil {
return fmt.Errorf("File already exists at path '%s'. Specify `--force` to overwrite", filePath)
}
} else {
os.Remove(filePath)
}
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
job, err := id.Backup(service)
if err != nil {
return err
}
logrus.Printf("Export started (job ID = %s)", job.ID)
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte("Polling until export finishes."))
status, err := ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nEnded in status '%s'", job.Status)
if job.Status != "finished" {
id.DumpLogs("backup", job, service)
return fmt.Errorf("Job finished with invalid status %s", job.Status)
}
err = id.Export(filePath, job, service)
if err != nil {
return err
}
err = id.DumpLogs("backup", job, service)
if err != nil {
return err
}
logrus.Printf("%s exported successfully to %s", service.Name, filePath)
return nil
}