func (a *rethinkAPIServer) InspectJob(ctx context.Context, request *ppsclient.InspectJobRequest) (response *persist.JobInfo, err error) { defer func(start time.Time) { a.Log(request, response, err, time.Since(start)) }(time.Now()) if request.Job == nil { return nil, fmt.Errorf("request.Job cannot be nil") } jobInfo := &persist.JobInfo{} var mustHaveFields []interface{} if request.BlockState { mustHaveFields = append(mustHaveFields, "State") } if err := a.waitMessageByPrimaryKey( jobInfosTable, request.Job.ID, jobInfo, func(jobInfo gorethink.Term) gorethink.Term { if request.BlockState { return gorethink.Or( jobInfo.Field("State").Eq(ppsclient.JobState_JOB_SUCCESS), jobInfo.Field("State").Eq(ppsclient.JobState_JOB_FAILURE)) } return gorethink.Expr(true) }, ); err != nil { return nil, err } return jobInfo, nil }
func (rd *rethinkDriver) PutBuild(build *datastore.Build) (string, error) { result, err := r.Table("builds").Insert( r.Table("builds").Filter( r.And( r.Row.Field("job_id").Eq(build.JobId), r.Row.Field("number").Eq(build.Number), ), ).CoerceTo("array").Do(func(docs r.Term) interface{} { return r.Branch( r.Or(docs.IsEmpty(), docs.Field("id").Contains(build.Id)), build, r.Error("Build with job_id and number exists"), ) }), r.InsertOpts{Conflict: "replace"}, ).RunWrite(rd.session) if err != nil { return "", err } if len(result.GeneratedKeys) > 0 { return result.GeneratedKeys[0], nil } else { return build.Id, nil } }
func (rd rethinkDriver) PutJob(job *datastore.Job) (string, error) { result, err := r.Table("jobs").Insert( r.Table("jobs").Filter(r.Row.Field("key").Eq(job.Key)).CoerceTo("array").Do(func(docs r.Term) interface{} { return r.Branch( r.Or(docs.IsEmpty(), docs.Field("id").Contains(job.Id)), job, r.Error("Job with key exists"), ) }), r.InsertOpts{Conflict: "replace"}, ).RunWrite(rd.session) if err != nil { return "", err } if len(result.GeneratedKeys) > 0 { return result.GeneratedKeys[0], nil } else { return job.Id, nil } }