Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT][API] Retrieve all jobs executed by the current user #78

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

[FEAT][API] Retrieve all jobs executed by the current user #78

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Member

youen commented Mar 31, 2024

Description

Retrieve all jobs executed by the current user.

Request

Method

GET

URL

/jobs

Request Parameters

Parameter Description Required Example
nb_days Number of days to go back in time to retrieve jobs. No 10

Request Body

None

Result

Result parameters

Parameter Description
id Job ID
kind Job kind
created_at Job creation date
status Job status
error_message Job error message
traceback Job traceback
result Job result
parameters Job parameters
current_progress Job current progress

Result Body

The response body is a JSON array of job objects.

Example Curl Request

Request

curl -X GET http://localhost:8080/jobs -H "Authorization: Bearer <access_token>"

Curl Response

[
  {
    "id": "12345678-90ab-cdef-0123-456789abcdef",
    "kind": "training",
    "created_at": "2023-03-08T16:32:10.123Z",
    "status": "finished",
    "error_message": null,
    "traceback": null,
    "result": {
      "accuracy": 0.95
    },
    "parameters": {
      "dataset": "my_dataset",
      "model": "my_model"
    },
    "current_progress": null
  }
]

Go server

Struct

type GenericJob struct {
	ID             string `json:"id"`
	Kind           string `json:"kind"`
	CreatedAt      time.Time `json:"created_at"`
	Status         string `json:"status"`
	ErrorMessage   *string `json:"error_message"`
	Traceback      *string `json:"traceback"`
	Result         interface{} `json:"result,omitempty"`
	Parameters     interface{} `json:"parameters,omitempty"`
	CurrentProgress *struct{} `json:"current_progress,omitempty"`
}

Handler

func (a *API) findJobsByUser(w http.ResponseWriter, r *http.Request) {
	jobs, err := a.jobsService.FindAllByUser(r.Context())
	if err != nil {
		RespondError(w, http.StatusInternalServerError, err)
		return
	}

	RespondJSON(w, http.StatusOK, jobs)
}
```JobKindTrain = JobKind("train")
	JobKindEval  = JobKind("eval")
	JobKindFeat  = JobKind("feat")
)

type JobStatus string

const (
	JobStatusDone    = JobStatus("done")
	JobStatusFailed  = JobStatus("failed")
	JobStatusRunning = JobStatus("running")
)

type JobProgress struct {
	TotalSteps   int `json:"total_steps"`
	CurrentStep  int `json:"current_step"`
}

Handler

func (h *APIHandler) GetJobsByUser(w http.ResponseWriter, r *http.Request) {
	nbDays := r.URL.Query().Get("nb_days")
	if nbDays == "" {
		nbDays = "5"
	}

	// Fetch the user from context
	user := h.getUserFromCtx(r.Context())
	if user == nil {
		h.respondWithError(w, http.StatusUnauthorized, errors.New("user authentication failed"))
		return
	}

	jobs, err := h.repo.GetJobsByUser(user.ID, nbDays)
	if err != nil {
		h.respondWithError(w, http.StatusInternalServerError, err)
		return
	}

	h.respondWithSuccess(w, http.StatusOK, jobs)
}

Links

Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant