Configurable background task execution

This commit is contained in:
Lorenzo Bolla
2021-09-08 15:50:54 +02:00
parent bd4c3a246d
commit 9b28d8984f
18 changed files with 427 additions and 214 deletions
+16 -1
View File
@@ -1,8 +1,11 @@
package api
import (
"fmt"
"net/http"
"strconv"
"github.com/aptly-dev/aptly/aptly"
"github.com/aptly-dev/aptly/task"
"github.com/gin-gonic/gin"
)
@@ -13,7 +16,7 @@ func apiTasksList(c *gin.Context) {
c.JSON(200, list.GetTasks())
}
// POST /tasks/clear
// POST /tasks-clear
func apiTasksClear(c *gin.Context) {
list := context.TaskList()
list.Clear()
@@ -120,3 +123,15 @@ func apiTasksDelete(c *gin.Context) {
c.JSON(200, delTask)
}
// POST /tasks-dummy
func apiTasksDummy(c *gin.Context) {
resources := []string{"dummy"}
taskName := fmt.Sprintf("Dummy task")
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (int, error) {
out.Printf("Dummy task started\n")
detail.Store([]int{1, 2, 3})
out.Printf("Dummy task finished\n")
return http.StatusTeapot, nil
})
}