|
1 | 1 | package handlers
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "bytes" |
5 | 4 | "encoding/json"
|
6 | 5 | "execution-service/constants"
|
| 6 | + "execution-service/messagequeue" |
7 | 7 | "execution-service/models"
|
8 | 8 | "execution-service/utils"
|
9 | 9 | "fmt"
|
| 10 | + "net/http" |
| 11 | + |
10 | 12 | "github.com/go-chi/chi/v5"
|
11 | 13 | "google.golang.org/api/iterator"
|
12 |
| - "net/http" |
13 |
| - "os" |
14 | 14 | )
|
15 | 15 |
|
16 | 16 | func (s *Service) ExecuteVisibleAndHiddenTestsAndSubmit(w http.ResponseWriter, r *http.Request) {
|
@@ -84,33 +84,39 @@ func (s *Service) ExecuteVisibleAndHiddenTestsAndSubmit(w http.ResponseWriter, r
|
84 | 84 | return
|
85 | 85 | }
|
86 | 86 |
|
87 |
| - // get history-service url from os env |
88 |
| - historyServiceUrl := os.Getenv("HISTORY_SERVICE_URL") |
89 |
| - if historyServiceUrl == "" { |
90 |
| - http.Error(w, "HISTORY_SERVICE_URL is not set", http.StatusInternalServerError) |
91 |
| - return |
92 |
| - } |
93 |
| - |
94 |
| - req, err := http.NewRequest(http.MethodPost, historyServiceUrl+"histories", |
95 |
| - bytes.NewBuffer(jsonData)) |
96 |
| - if err != nil { |
97 |
| - http.Error(w, err.Error(), http.StatusInternalServerError) |
98 |
| - return |
99 |
| - } |
100 |
| - |
101 |
| - req.Header.Set("Content-Type", "application/json") |
102 |
| - |
103 |
| - client := &http.Client{} |
104 |
| - resp, err := client.Do(req) |
| 87 | + err = messagequeue.PublishSubmissionMessage(jsonData) |
105 | 88 | if err != nil {
|
106 |
| - http.Error(w, err.Error(), http.StatusInternalServerError) |
| 89 | + http.Error(w, fmt.Sprintf("Failed to save submission history: %v", err), http.StatusInternalServerError) |
107 | 90 | return
|
108 | 91 | }
|
109 |
| - defer resp.Body.Close() |
110 | 92 |
|
111 |
| - if resp.StatusCode != http.StatusOK { |
112 |
| - http.Error(w, "Failed to save submission history", http.StatusInternalServerError) |
113 |
| - } |
| 93 | + // get history-service url from os env |
| 94 | + // historyServiceUrl := os.Getenv("HISTORY_SERVICE_URL") |
| 95 | + // if historyServiceUrl == "" { |
| 96 | + // http.Error(w, "HISTORY_SERVICE_URL is not set", http.StatusInternalServerError) |
| 97 | + // return |
| 98 | + // } |
| 99 | + |
| 100 | + // req, err := http.NewRequest(http.MethodPost, historyServiceUrl+"histories", |
| 101 | + // bytes.NewBuffer(jsonData)) |
| 102 | + // if err != nil { |
| 103 | + // http.Error(w, err.Error(), http.StatusInternalServerError) |
| 104 | + // return |
| 105 | + // } |
| 106 | + |
| 107 | + // req.Header.Set("Content-Type", "application/json") |
| 108 | + |
| 109 | + // client := &http.Client{} |
| 110 | + // resp, err := client.Do(req) |
| 111 | + // if err != nil { |
| 112 | + // http.Error(w, err.Error(), http.StatusInternalServerError) |
| 113 | + // return |
| 114 | + // } |
| 115 | + // defer resp.Body.Close() |
| 116 | + |
| 117 | + // if resp.StatusCode != http.StatusOK { |
| 118 | + // http.Error(w, "Failed to save submission history", http.StatusInternalServerError) |
| 119 | + // } |
114 | 120 |
|
115 | 121 | w.Header().Set("Content-Type", "application/json")
|
116 | 122 | w.WriteHeader(http.StatusOK)
|
|
0 commit comments