github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/jobs/stop.go (about) 1 package jobs 2 3 import ( 4 "fmt" 5 6 "github.com/Sirupsen/logrus" 7 "github.com/daticahealth/cli/commands/services" 8 "github.com/daticahealth/cli/lib/prompts" 9 ) 10 11 func CmdStop(jobID string, svcName string, ij IJobs, is services.IServices, force bool, ip prompts.IPrompts) error { 12 if !force { 13 err := ip.YesNo(fmt.Sprintf("Stopping %s %s will immediately stop this job.", svcName, jobID), fmt.Sprintf("Are you sure you want to stop %s? (y/n) ", svcName)) 14 if err != nil { 15 return err 16 } 17 } 18 19 service, err := is.RetrieveByLabel(svcName) 20 if err != nil { 21 return err 22 } 23 if service == nil { 24 return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"datica services list\" command.", svcName) 25 } 26 err = ij.Stop(jobID, service.ID) 27 if err != nil { 28 return err 29 } 30 logrus.Printf("Job '%s' will be stopped in 15 seconds.", jobID) 31 return nil 32 } 33 34 func (j *SJobs) Stop(jobID string, svcID string) error { 35 36 headers := j.Settings.HTTPManager.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID) 37 resp, statusCode, err := j.Settings.HTTPManager.Post(nil, 38 fmt.Sprintf("%s%s/environments/%s/services/%s/jobs/%s/stop", 39 j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, jobID), headers) 40 if err != nil { 41 return err 42 } 43 44 return j.Settings.HTTPManager.ConvertResp(resp, statusCode, nil) 45 46 }