New route to launch action individually
This commit is contained in:
parent
d202cdfee8
commit
05c87ac7b3
3 changed files with 62 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -90,4 +91,23 @@ func declareActionsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||
|
||||
c.JSON(http.StatusOK, nil)
|
||||
})
|
||||
|
||||
actionsRoutes.POST("/run", func(c *gin.Context) {
|
||||
action := c.MustGet("action").(*reveil.Action)
|
||||
|
||||
cmd, err := action.Launch()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to run the action: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := cmd.Wait()
|
||||
if err != nil {
|
||||
log.Printf("%q: %s", action.Name, err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue