@@ -3,6 +3,7 @@ package controller
33import (
44 "net/http"
55
6+ "github.com/cloud-barista/cm-cicada/lib/cmd"
67 "github.com/cloud-barista/cm-cicada/lib/ssh"
78 "github.com/cloud-barista/cm-cicada/pkg/api/rest/common"
89 "github.com/cloud-barista/cm-cicada/pkg/api/rest/model"
@@ -58,3 +59,39 @@ func RunScript(c echo.Context) error {
5859
5960 return c .JSONPretty (http .StatusOK , result , " " )
6061}
62+
63+ // SleepTime godoc
64+ //
65+ // @ID sleep-time
66+ // @Summary Run sleep command on cicada
67+ // @Description Runs sleep command on cicada and waits for configured time.
68+ // @Tags [Cicada Task Component]
69+ // @Accept json
70+ // @Produce json
71+ // @Param request body model.SleepTimeReq true "SleepTime request"
72+ // @Success 200 {object} model.ScriptResult "Result of sleep"
73+ // @Failure 400 {object} common.ErrorResponse "Sent bad request."
74+ // @Failure 500 {object} common.ErrorResponse "Failed to run script"
75+ // @Router /sleep_time [post]
76+ func SleepTime (c echo.Context ) error {
77+ sleepTimeReq := new (model.SleepTimeReq )
78+ err := c .Bind (sleepTimeReq )
79+ if err != nil {
80+ return err
81+ }
82+
83+ if sleepTimeReq .Time == "" {
84+ return common .ReturnErrorMsg (c , "Please provide the time." )
85+ }
86+
87+ var result model.SimpleMsg
88+
89+ _ , err = cmd .RunBash ("sleep " + sleepTimeReq .Time )
90+ if err != nil {
91+ result .Message = err .Error ()
92+ } else {
93+ result .Message = "success"
94+ }
95+
96+ return c .JSONPretty (http .StatusOK , result , " " )
97+ }
0 commit comments