Skip to content

Commit

Permalink
[Aishwarya|Jenson] fix callback URL support for job execution API
Browse files Browse the repository at this point in the history
  • Loading branch information
AishwaryaRK authored and jensoncs committed Feb 12, 2019
1 parent 919f124 commit 1ed090e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 12 additions & 4 deletions proctord/jobs/execution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (handler *executionHandler) Handle() http.HandlerFunc {
jobsExecutionAuditLog := &postgres.JobsExecutionAuditLog{
JobExecutionStatus: "WAITING",
}
defer func() { go handler.auditor.JobsExecutionAndStatus(jobsExecutionAuditLog) }()

userEmail := req.Header.Get(utility.UserEmailHeaderKey)
jobsExecutionAuditLog.UserEmail = userEmail
Expand All @@ -79,32 +78,41 @@ func (handler *executionHandler) Handle() http.HandlerFunc {

w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(utility.ClientError))
go handler.auditor.JobsExecutionAndStatus(jobsExecutionAuditLog)

return
}

jobExecutionID, err := handler.executioner.Execute(jobsExecutionAuditLog, job.Name, job.Args)
if err != nil {
logger.Error(fmt.Sprintf("%s: User %s: Error executing job: ", job.Name, userEmail), err.Error())
raven.CaptureError(err, map[string]string{"user_email": userEmail, "job_name": job.Name})

jobsExecutionAuditLog.Errors = fmt.Sprintf("Error executing job: %s", err.Error())
jobsExecutionAuditLog.JobSubmissionStatus = utility.JobSubmissionServerError
go handler.auditor.JobsExecutionAndStatus(jobsExecutionAuditLog)

w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(utility.ServerError))

return
}

w.WriteHeader(http.StatusCreated)
w.Write([]byte(fmt.Sprintf("{ \"name\":\"%s\" }", jobExecutionID)))

remoteCallerURL := job.CallbackApi
go handler.sendStatusToCaller(remoteCallerURL, jobExecutionID)

go handler.postJobExecute(jobsExecutionAuditLog, remoteCallerURL, jobExecutionID)
return
}
}

func (handler *executionHandler) postJobExecute(jobsExecutionAuditLog *postgres.JobsExecutionAuditLog, remoteCallerURL, jobExecutionID string) {
handler.auditor.JobsExecutionAndStatus(jobsExecutionAuditLog)
if remoteCallerURL != "" {
handler.sendStatusToCaller(remoteCallerURL, jobExecutionID)
}
}

func (handler *executionHandler) sendStatusToCaller(remoteCallerURL, jobExecutionID string) {
status := utility.JobWaiting

Expand Down
6 changes: 1 addition & 5 deletions proctord/jobs/execution/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ func (suite *ExecutionHandlerTestSuite) TestSuccessfulJobExecutionHandler() {
func(args mock.Arguments) { auditingChan <- true },
)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
}))
defer ts.Close()

suite.mockStore.On("GetJobExecutionStatus", jobExecutionID).Return(utility.JobSucceeded, nil).Once()

suite.testExecutionHandler.Handle()(responseRecorder, req)
Expand Down Expand Up @@ -111,6 +106,7 @@ func (suite *ExecutionHandlerTestSuite) TestJobExecutionServerFailure() {
job := Job{
Name: "sample-job-name",
Args: map[string]string{"argOne": "sample-arg"},

}

requestBody, err := json.Marshal(job)
Expand Down

0 comments on commit 1ed090e

Please sign in to comment.