func (r *runner) Start(pipelineRunID string) error { pipelineRun, err := r.storeClient.GetPipelineRun(pipelineRunID) if err != nil { return err } pipeline, err := r.storeClient.GetPipeline(pipelineRun.PipelineId) if err != nil { return err } nameToNodeInfo, err := getNameToNodeInfo(pipeline.NameToNode) if err != nil { return err } nameToNodeFunc := make(map[string]func() error) for name, node := range pipeline.NameToNode { nodeFunc, err := r.getNodeFunc( pipelineRun.Id, name, node, pipeline.NameToDockerService, //dirPath, 1, ) if err != nil { return err } nameToNodeFunc[name] = nodeFunc } run, err := r.grapher.Build( nameToNodeInfo, nameToNodeFunc, ) if err != nil { return err } if err := r.storeClient.CreatePipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_STARTED); err != nil { return err } go func() { if err := run.Do(); err != nil { protolog.Errorln(err.Error()) if storeErr := r.storeClient.CreatePipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_ERROR); storeErr != nil { protolog.Errorln(storeErr.Error()) } } else { if storeErr := r.storeClient.CreatePipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_SUCCESS); storeErr != nil { protolog.Errorln(storeErr.Error()) } } }() return nil }
func (p *pipelineController) Start() error { // TODO: do not get all jobs each time, need a limit call on persist, more // generally, need all persist calls to have a limit jobInfos, err := p.jobAPIClient.ListJob(context.Background(), &pps.ListJobRequest{Pipeline: p.pipelineInfo.Pipeline}) if err != nil { return err } lastCommit := &pfs.Commit{ Repo: p.pipelineInfo.Input, // TODO: use initial commit id when moved to pfs package Id: "scratch", } if len(jobInfos.JobInfo) > 0 { lastCommit = jobInfos.JobInfo[0].Input } p.waitGroup.Add(1) go func() { defer p.waitGroup.Done() if err := p.run(lastCommit); ignoreCanceledError(err) != nil { // TODO: what to do with error? protolog.Errorln(err.Error()) } }() return nil }
func (j *jobRunner) Start(persistJobInfo *persist.JobInfo) error { if _, err := j.persistAPIClient.CreateJobStatus( context.Background(), &persist.JobStatus{ JobId: persistJobInfo.JobId, Type: pps.JobStatusType_JOB_STATUS_TYPE_STARTED, }, ); err != nil { return err } // TODO: throttling? worker pool? go func() { if err := j.runJobInfo(persistJobInfo); err != nil { protolog.Errorln(err.Error()) // TODO: how to handle the error? if _, err = j.persistAPIClient.CreateJobStatus( context.Background(), &persist.JobStatus{ JobId: persistJobInfo.JobId, Type: pps.JobStatusType_JOB_STATUS_TYPE_ERROR, Message: err.Error(), }, ); err != nil { protolog.Errorln(err.Error()) } } else { // TODO: how to handle the error? if _, err = j.persistAPIClient.CreateJobStatus( context.Background(), &persist.JobStatus{ JobId: persistJobInfo.JobId, Type: pps.JobStatusType_JOB_STATUS_TYPE_SUCCESS, }, ); err != nil { protolog.Errorln(err.Error()) } } }() return nil }
func (r *runner) Start(pipelineSource *pps.PipelineSource) (string, error) { dirPath, pipeline, err := r.sourcer.GetDirPathAndPipeline(pipelineSource) if err != nil { return "", err } pipelineRunID := strings.Replace(uuid.NewV4().String(), "-", "", -1) pipelineRun := &pps.PipelineRun{ Id: pipelineRunID, Pipeline: pipeline, PipelineSource: pipelineSource, } if err := r.storeClient.AddPipelineRun(pipelineRun); err != nil { return "", err } protolog.Info( &AddedPipelineRun{ PipelineRun: pipelineRun, }, ) nameToNode := pps.GetNameToNode(pipeline) nameToDockerService := pps.GetNameToDockerService(pipeline) nameToNodeInfo, err := getNameToNodeInfo(nameToNode) if err != nil { return "", err } nameToNodeFunc := make(map[string]func() error) for name, node := range nameToNode { nodeFunc, err := r.getNodeFunc( pipelineRunID, name, node, nameToDockerService, dirPath, 1, ) if err != nil { return "", err } nameToNodeFunc[name] = nodeFunc } run, err := r.grapher.Build( nameToNodeInfo, nameToNodeFunc, ) if err != nil { return "", err } if err := r.storeClient.AddPipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_STARTED); err != nil { return "", err } go func() { if err := run.Do(); err != nil { if storeErr := r.storeClient.AddPipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_ERROR); storeErr != nil { protolog.Errorln(storeErr.Error()) } } else { if storeErr := r.storeClient.AddPipelineRunStatus(pipelineRunID, pps.PipelineRunStatusType_PIPELINE_RUN_STATUS_TYPE_SUCCESS); storeErr != nil { protolog.Errorln(storeErr.Error()) } } }() return pipelineRunID, nil }