44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package execution
|
|
|
|
import (
|
|
"go.laravel.com/db"
|
|
"go.laravel.com/inertia"
|
|
"go.laravel.com/model"
|
|
"go.laravel.com/web"
|
|
|
|
"app/models"
|
|
"app/services"
|
|
)
|
|
|
|
func Show(request *web.Request) *web.Response {
|
|
id, err := request.PathInt("execution")
|
|
if err != nil {
|
|
return web.Fail(err)
|
|
}
|
|
execution, err := model.Query[models.OperationExecution]().Find(request, id)
|
|
if err != nil {
|
|
return web.Fail(err)
|
|
}
|
|
proposal, err := model.Query[models.RemediationProposal]().Find(request, execution.ProposalID)
|
|
if err != nil {
|
|
return web.Fail(err)
|
|
}
|
|
remote, err := services.From(request.Context()).Jeannie.Execution(request.Context(), execution.JeannieExecutionID)
|
|
if err != nil {
|
|
return web.Fail(err)
|
|
}
|
|
if err := model.Update(request, &execution, db.Values{
|
|
"status": remote.Status, "output": remote.Output, "error": remote.Error,
|
|
}); err != nil {
|
|
return web.Fail(err)
|
|
}
|
|
if remote.Status == "succeeded" || remote.Status == "failed" {
|
|
if err := model.Update(request, &proposal, db.Values{"status": remote.Status}); err != nil {
|
|
return web.Fail(err)
|
|
}
|
|
}
|
|
return inertia.Render("Execution", inertia.Props{
|
|
"view": inertia.Props{"execution": execution, "proposal": proposal},
|
|
})
|
|
}
|