Skip to content

Commit

Permalink
proper job handling for failed and expired jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusDieckmann committed May 26, 2021
1 parent e6ae450 commit 9bcd365
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .kube/dev-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
secretKeyRef:
key: Token
name: authhandler
image: harbor.computational.bio.uni-giessen.de/bakta/bakta-web-backend:0.2.9-beta.35
image: harbor.computational.bio.uni-giessen.de/bakta/bakta-web-backend:0.2.9-beta.36
imagePullPolicy: Always
name: baktabackend
ports:
Expand Down
6 changes: 1 addition & 5 deletions database/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,8 @@ func (handler *Handler) GetJobs(jobIDs []*api.JobAuth) ([]Job, error) {
var jobRequests []bson.M

for _, jobRequest := range jobIDs {
secretSHA := sha256.Sum256([]byte(jobRequest.Secret))
secretSHABase64 := base64.StdEncoding.EncodeToString(secretSHA[:])

jobRequests = append(jobRequests, bson.M{
"jobid": jobRequest.JobID,
"secret": secretSHABase64,
"jobid": jobRequest.JobID,
})
}

Expand Down
28 changes: 28 additions & 0 deletions endpoints/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package endpoints

import (
"context"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -111,8 +113,34 @@ func (apiHandler *BaktaJobAPI) GetJobsStatus(ctx context.Context, request *api.J
return nil, err
}

foundJob := make(map[string]*database.Job)

var jobsStatus []*api.JobStatusResponse
for _, job := range jobs {
foundJob[job.JobID] = &job

}

for _, expectedJob := range jobs {
job, ok := foundJob[expectedJob.JobID]
if !ok {
failedJobs = append(failedJobs, &api.FailedJob{
JobID: expectedJob.JobID,
JobStatus: api.JobFailedStatus_NOT_FOUND,
})
continue
}
secretSHA := sha256.Sum256([]byte(job.Secret))
secretSHABase64 := base64.StdEncoding.EncodeToString(secretSHA[:])

if secretSHABase64 != expectedJob.Secret {
failedJobs = append(failedJobs, &api.FailedJob{
JobID: expectedJob.JobID,
JobStatus: api.JobFailedStatus_UNAUTHORIZED,
})
continue
}

statusNumber, ok := api.JobStatusEnum_value[job.Status]
if !ok {
err = fmt.Errorf("%v not a valid status", job.Status)
Expand Down

0 comments on commit 9bcd365

Please sign in to comment.