本文整理匯總了Golang中github.com/catalyzeio/cli/lib/jobs.IJobs.DeployTarget方法的典型用法代碼示例。如果您正苦於以下問題:Golang IJobs.DeployTarget方法的具體用法?Golang IJobs.DeployTarget怎麽用?Golang IJobs.DeployTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/catalyzeio/cli/lib/jobs.IJobs
的用法示例。
在下文中一共展示了IJobs.DeployTarget方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}