Skip to content

Commit

Permalink
Add endpoint to get taskInfo via REST
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjndw committed Aug 7, 2024
1 parent cea0f5e commit 37e5085
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
27 changes: 26 additions & 1 deletion HadesAPI/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func setupRouter(auth_key string) *gin.Engine {

r.GET("/ping", ping)
r.POST("/build", AddBuildToQueue)
r.GET("/task/:id", GetTaskState)
return r
}

Expand Down Expand Up @@ -80,6 +81,30 @@ func AddBuildToQueue(c *gin.Context) {
log.Printf(" [*] Successfully enqueued job: %+v", info.ID)
c.JSON(http.StatusOK, gin.H{
"message": "Successfully enqueued job",
"job_id": payload.QueuePayload.ID.String(),
"task_id": info.ID,
"job_id": payload.QueuePayload.ID,
})
}

func GetTaskState(c *gin.Context) {
id := c.Param("id")
if id == "" {
c.String(http.StatusBadRequest, "No task ID provided")
return
}
inspector := asynq.NewInspector(asynq.RedisClientOpt{Addr: cfg.RedisConfig.Addr, Password: cfg.RedisConfig.Pwd})
queues, err := inspector.Queues()
if err != nil {
log.WithError(err).Error("Failed to get queues")
c.String(http.StatusInternalServerError, "Failed to get queues")
return
}
for _, q := range queues {
taskInfo, err := inspector.GetTaskInfo(q, id)
if err == nil {
c.JSON(http.StatusOK, taskInfo.State.String())
return
}
}
c.String(http.StatusNotFound, "Task not found")
}
57 changes: 57 additions & 0 deletions docs/api/Get Status of Build Job.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
meta {
name: Get Status of Build Job
type: http
seq: 2
}

get {
url: http://{{hostname}}/task/:id
body: json
auth: none
}

params:path {
id: 08df9951-1a86-4ac4-ac7a-7c3ec5d322af
}

body:json {
{
"name": "Example Job",
"metadata": {}, // global metadata
"timestamp": "2021-01-01T00:00:00.000Z",
"priority": 3, // optional, default 3
"steps": [
{
"id": 1, // mandatory to declare the order of execution
"name": "Clone",
"image": "ghcr.io/ls1intum/hades/hades-clone-container:latest", // mandatory
"metadata": {
"REPOSITORY_DIR": "/shared",
"HADES_TEST_USERNAME": "{{user}}",
"HADES_TEST_PASSWORD": "{{password}}",
"HADES_TEST_URL": "{{test_repo}}",
"HADES_TEST_PATH": "./example",
"HADES_TEST_ORDER": "1",
"HADES_ASSIGNMENT_USERNAME": "{{user}}",
"HADES_ASSIGNMENT_PASSWORD": "{{password}}",
"HADES_ASSIGNMENT_URL": "{{assignment_repo}}",
"HADES_ASSIGNMENT_PATH": "./example/assignment",
"HADES_ASSIGNMENT_ORDER": "2"
}
},
{
"id": 2, // mandatory to declare the order of execution
"name": "Execute",
"image": "ls1tum/artemis-maven-template:java17-18", // mandatory
"script": "cd ./example && ./gradlew --status && ./gradlew clean test"
}
]
}
}

vars:pre-request {
user: {{process.env.USERNAME}}
password: {{process.env.PASSWORD}}
test_repo: {{process.env.TEST_REPO}}
assignment_repo: {{process.env.ASSIGNMENT_REPO}}
}

0 comments on commit 37e5085

Please sign in to comment.