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