• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang jobs.IJobs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/catalyzeio/cli/lib/jobs.IJobs的典型用法代码示例。如果您正苦于以下问题:Golang IJobs类的具体用法?Golang IJobs怎么用?Golang IJobs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了IJobs类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:catalyzeio,项目名称:cli,代码行数:33,代码来源:backup.go


示例2: CmdDeploy

func CmdDeploy(svcName, target string, iw IWorker, is services.IServices, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(svcName)
	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 list\" command.", svcName)
	}
	logrus.Printf("Initiating a worker for service %s (procfile target = \"%s\")", svcName, target)
	workers, err := iw.Retrieve(service.ID)
	if err != nil {
		return err
	}
	if _, ok := workers.Workers[target]; ok {
		logrus.Printf("Worker with target %s for service %s is already running, deploying another worker", target, svcName)
	}
	workers.Workers[target]++
	err = iw.Update(service.ID, workers)
	if err != nil {
		return err
	}
	err = ij.DeployTarget(target, service.ID)
	if err != nil {
		return err
	}
	logrus.Printf("Successfully deployed a worker for service %s with target %s", svcName, target)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:28,代码来源:deploy.go


示例3: CmdRollback

func CmdRollback(svcName, releaseName string, ij jobs.IJobs, irs releases.IReleases, is services.IServices) error {
	if strings.ContainsAny(releaseName, config.InvalidChars) {
		return fmt.Errorf("Invalid release name. Names must not contain the following characters: %s", config.InvalidChars)
	}
	service, err := is.RetrieveByLabel(svcName)
	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.", svcName)
	}
	logrus.Printf("Rolling back %s to %s", svcName, releaseName)
	release, err := irs.Retrieve(releaseName, service.ID)
	if err != nil {
		return err
	}
	if release == nil {
		return fmt.Errorf("Could not find a release with the name \"%s\". You can list releases for this code service with the \"catalyze releases list %s\" command.", releaseName, svcName)
	}
	err = ij.DeployRelease(releaseName, service.ID)
	if err != nil {
		return err
	}
	logrus.Println("Rollback successful! Check the status with \"catalyze status\" and your logging dashboard for updates.")
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:26,代码来源:rollback.go


示例4: CmdRm

func CmdRm(svcName, target string, iw IWorker, is services.IServices, ip prompts.IPrompts, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(svcName)
	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 list\" command.", svcName)
	}
	err = ip.YesNo(fmt.Sprintf("Removing the worker target %s for service %s will automatically stop all existing worker jobs with that target, would you like to proceed? (y/n) ", target, svcName))
	if err != nil {
		return err
	}
	jobs, err := ij.RetrieveByTarget(service.ID, target, 1, 1000)
	if err != nil {
		return err
	}
	for _, j := range *jobs {
		err = ij.Delete(j.ID, service.ID)
		if err != nil {
			return err
		}
	}
	workers, err := iw.Retrieve(service.ID)
	if err != nil {
		return err
	}
	delete(workers.Workers, target)
	err = iw.Update(service.ID, workers)
	if err != nil {
		return err
	}
	logrus.Printf("Successfully removed all workers with target %s for service %s", target, svcName)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:34,代码来源:rm.go


示例5: 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
}
开发者ID:catalyzeio,项目名称:cli,代码行数:56,代码来源:import.go


示例6: CmdList

func CmdList(svcName string, iw IWorker, is services.IServices, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(svcName)
	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 list\" command.", svcName)
	}
	workers, err := iw.Retrieve(service.ID)
	if err != nil {
		return err
	}

	jobs, err := ij.RetrieveByType(service.ID, "worker", 1, 1000)
	if err != nil {
		return err
	}
	type workerJob struct {
		scale   int
		running int
	}
	var workerJobs = map[string]*workerJob{}
	for target, scale := range workers.Workers {
		workerJobs[target] = &workerJob{scale, 0}
	}
	if len(workerJobs) == 0 {
		logrus.Printf("No workers found for service %s", svcName)
		return nil
	}
	for _, j := range *jobs {
		if _, ok := workerJobs[j.Target]; !ok {
			workerJobs[j.Target] = &workerJob{0, 0}
		}
		if j.Status == "running" {
			workerJobs[j.Target].running = 1
		}
	}

	data := [][]string{{"TARGET", "SCALE", "RUNNING JOBS"}}
	for target, wj := range workerJobs {
		data = append(data, []string{target, fmt.Sprintf("%d", wj.scale), fmt.Sprintf("%d", wj.running)})
	}

	table := tablewriter.NewWriter(logrus.StandardLogger().Out)
	table.SetBorder(false)
	table.SetRowLine(false)
	table.SetCenterSeparator("")
	table.SetColumnSeparator("")
	table.SetRowSeparator("")
	table.AppendBulk(data)
	table.Render()
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:53,代码来源:list.go


示例7: CmdLogs

func CmdLogs(databaseName, backupID string, 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 := ij.Retrieve(backupID, service.ID, false)
	if err != nil {
		return err
	}
	return id.DumpLogs("backup", job, service)
}
开发者ID:catalyzeio,项目名称:cli,代码行数:14,代码来源:logs.go


示例8: 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
}
开发者ID:catalyzeio,项目名称:cli,代码行数:48,代码来源:export.go


示例9: CmdStop

// CmdStop stops all instances of a given service. All workers and rake tasks will also be stopped
// if applicable.
func CmdStop(svcName string, is IServices, ij jobs.IJobs, ip prompts.IPrompts) error {
	err := ip.YesNo(fmt.Sprintf("Are you sure you want to stop %s? This will stop all instances of the service, all workers, all rake tasks, and all currently open consoles. (y/n) ", svcName))
	if err != nil {
		return err
	}
	service, err := is.RetrieveByLabel(svcName)
	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 list\" command.", svcName)
	}
	if !service.Redeployable {
		return fmt.Errorf("This service cannot be stopped. Please contact Catalyze Support at [email protected] if you need the \"%s\" service stopped.", svcName)
	}

	page := 0
	pageSize := 100
	for {
		jobs, err := ij.List(service.ID, page, pageSize)
		if err != nil {
			return err
		}

		for _, job := range *jobs {
			if job.Status != "scheduled" && job.Status != "queued" && job.Status != "started" && job.Status != "running" && job.Status != "waiting" {
				logrus.Debugf("Skipping %s job (%s)", job.Status, job.ID)
				continue
			}
			logrus.Debugf("Deleting %s job (%s) on service %s", job.Type, job.ID, service.ID)
			err = ij.Delete(job.ID, service.ID)
			if err != nil {
				return err
			}
		}
		if len(*jobs) < pageSize {
			break
		}
		page++
	}

	logrus.Printf("Successfully stopped %s. Run \"catalyze redeploy %s\" to start this service again.", svcName, svcName)
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:46,代码来源:stop.go


示例10: CmdRedeploy

func CmdRedeploy(envID, svcName string, ij jobs.IJobs, is services.IServices, ie environments.IEnvironments) error {
	env, err := ie.Retrieve(envID)
	if err != nil {
		return err
	}
	service, err := is.RetrieveByLabel(svcName)
	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.", svcName)
	}
	logrus.Printf("Redeploying service %s (ID = %s) in environment %s (ID = %s)", svcName, service.ID, env.Name, env.ID)
	err = ij.Redeploy(service.ID)
	if err != nil {
		return err
	}
	logrus.Println("Redeploy successful! Check the status with \"catalyze status\" and your logging dashboard for updates")
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:20,代码来源:redeploy.go


示例11: CmdScale

func CmdScale(svcName, target, scaleString string, iw IWorker, is services.IServices, ip prompts.IPrompts, ij jobs.IJobs) error {
	service, err := is.RetrieveByLabel(svcName)
	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 list\" command.", svcName)
	}
	scaleFunc, changeInScale, err := iw.ParseScale(scaleString)
	if err != nil {
		return err
	}
	workers, err := iw.Retrieve(service.ID)
	if err != nil {
		return err
	}
	scale := scaleFunc(workers.Workers[target], changeInScale)
	if existingScale, ok := workers.Workers[target]; !ok || scale > existingScale {
		logrus.Printf("Deploying %d new workers with target %s for service %s", scale-existingScale, target, svcName)
		workers.Workers[target] = scale
		err = iw.Update(service.ID, workers)
		if err != nil {
			return err
		}
		err = ij.DeployTarget(target, service.ID)
		if err != nil {
			return err
		}
		logrus.Printf("Successfully deployed %d new workers with target %s for service %s and set the scale to %d", scale-existingScale, target, svcName, scale)
	} else if scale < existingScale {
		err = ip.YesNo(fmt.Sprintf("Scaling down the %s target from %d to %d for service %s will automatically stop %d jobs, would you like to proceed? (y/n) ", target, existingScale, scale, svcName, existingScale-scale))
		if err != nil {
			return err
		}
		jobs, err := ij.RetrieveByTarget(service.ID, target, 1, 1000)
		if err != nil {
			return err
		}
		deleteLimit := existingScale - scale
		deleted := 0

		for _, j := range *jobs {
			err = ij.Delete(j.ID, service.ID)
			if err != nil {
				return err
			}
			deleted++
			if deleted == deleteLimit {
				break
			}
		}
		workers.Workers[target] = scale
		err = iw.Update(service.ID, workers)
		if err != nil {
			return err
		}
		logrus.Printf("Successfully removed %d existing workers with target %s for service %s and set the scale to %d", existingScale-scale, target, svcName, scale)
	} else {
		logrus.Printf("Worker target %s for service %s is already at a scale of %d", target, svcName, scale)
	}
	return nil
}
开发者ID:catalyzeio,项目名称:cli,代码行数:62,代码来源:scale.go



注:本文中的github.com/catalyzeio/cli/lib/jobs.IJobs类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang prompts.IPrompts类代码示例发布时间:2022-05-23
下一篇:
Golang httpclient.GetHeaders函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap