Skip to content

Commit

Permalink
patch for run handler and endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
acashmoney committed Sep 13, 2023
1 parent 7838c44 commit 2978e8b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion gateway/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/gorilla/mux v1.8.0
github.com/labdao/plex v0.10.1
github.com/labdao/plex v0.10.4
github.com/rs/cors v1.9.0
gorm.io/driver/postgres v1.5.2
gorm.io/gorm v1.25.4
Expand Down
4 changes: 2 additions & 2 deletions gateway/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labdao/plex v0.10.1 h1:54rs4YYfiCbDgGPK22k4OhoNIQfBjGF0g7kLyhhutAg=
github.com/labdao/plex v0.10.1/go.mod h1:i28o1TNadeID2LCspFOYCQ8ynaaje/Jr+svKFZG+taY=
github.com/labdao/plex v0.10.4 h1:f758PFYa9Nw+AMH3GhmmURbnmJy9avs6ZLc4r/hsip0=
github.com/labdao/plex v0.10.4/go.mod h1:i28o1TNadeID2LCspFOYCQ8ynaaje/Jr+svKFZG+taY=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
Expand Down
77 changes: 38 additions & 39 deletions gateway/handlers/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"

Expand Down Expand Up @@ -78,44 +77,44 @@ func InitJobHandler(db *gorm.DB) http.HandlerFunc {
}
}

func RunJobHandler(db *gorm.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := utils.CheckRequestMethod(r, http.MethodPost); err != nil {
utils.SendJSONError(w, err.Error(), http.StatusBadRequest)
return
}

var requestData struct {
IoJsonCid string `json:"ioJsonCid"`
Annotations []string `json:"annotations"`
}

if err := utils.ReadRequestBody(r, &requestData); err != nil {
http.Error(w, "Error parsing request body", http.StatusBadRequest)
return
}

tempDir, err := ioutil.TempDir("", "job")
if err != nil {
http.Error(w, fmt.Sprintf("Error creating temporary directory: %v", err), http.StatusInternalServerError)
return
}
defer os.RemoveAll(tempDir)

completedIoJsonCid, ioJsonPath, err := ipwl.RunIO(requestData.IoJsonCid, requestData.OutputDir, false, false, 60, 1, requestData.Annotations)
if err != nil {
http.Error(w, fmt.Sprintf("Error running job: %v", err), http.StatusInternalServerError)
return
}

responseData := map[string]string{
"completedIoJsonCid": completedIoJsonCid,
"ioJsonPath": ioJsonPath,
}

utils.SendJSONResponse(w, responseData)
}
}
// func RunJobHandler(db *gorm.DB) http.HandlerFunc {
// return func(w http.ResponseWriter, r *http.Request) {
// if err := utils.CheckRequestMethod(r, http.MethodPost); err != nil {
// utils.SendJSONError(w, err.Error(), http.StatusBadRequest)
// return
// }

// var requestData struct {
// IoJsonCid string `json:"ioJsonCid"`
// Annotations []string `json:"annotations"`
// }

// if err := utils.ReadRequestBody(r, &requestData); err != nil {
// http.Error(w, "Error parsing request body", http.StatusBadRequest)
// return
// }

// tempDir, err := ioutil.TempDir("", "job")
// if err != nil {
// http.Error(w, fmt.Sprintf("Error creating temporary directory: %v", err), http.StatusInternalServerError)
// return
// }
// defer os.RemoveAll(tempDir)

// completedIoJsonCid, ioJsonPath, err := ipwl.RunIO(requestData.IoJsonCid, requestData.OutputDir, false, false, 60, 1, requestData.Annotations)
// if err != nil {
// http.Error(w, fmt.Sprintf("Error running job: %v", err), http.StatusInternalServerError)
// return
// }

// responseData := map[string]string{
// "completedIoJsonCid": completedIoJsonCid,
// "ioJsonPath": ioJsonPath,
// }

// utils.SendJSONResponse(w, responseData)
// }
// }

func GetJobHandler(db *gorm.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion gateway/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewServer(db *gorm.DB) *mux.Router {
router.HandleFunc("/init-job", handlers.InitJobHandler(db)).Methods("POST")
router.HandleFunc("/get-jobs", handlers.GetJobsHandler(db)).Methods("GET")
router.HandleFunc("/get-jobs/{cid}", handlers.GetJobHandler(db)).Methods("GET")
router.HandleFunc("/run-job", handlers.RunJobHandler(db)).Methods("POST")
// router.HandleFunc("/run-job", handlers.RunJobHandler(db)).Methods("POST")

return router
}

0 comments on commit 2978e8b

Please sign in to comment.