diff --git a/.kubernetes/ingress.yaml b/.kubernetes/ingress.yaml index 391d37c..7be70cb 100644 --- a/.kubernetes/ingress.yaml +++ b/.kubernetes/ingress.yaml @@ -5,6 +5,9 @@ metadata: annotations: kubernetes.io/ingress.class: "nginx" nginx.ingress.kubernetes.io/enable-cors: "true" + nginx.ingress.kubernetes.io/proxy-connect-timeout: "7200" + nginx.ingress.kubernetes.io/proxy-send-timeout: "7200" + nginx.ingress.kubernetes.io/proxy-read-timeout: "7200" nginx.ingress.kubernetes.io/cors-allow-methods: "*" nginx.ingress.kubernetes.io/cors-allow-origin: "*" nginx.ingress.kubernetes.io/use-regex: "true" diff --git a/http-routes/http-routes.go b/http-routes/http-routes.go index 34f139c..52f6c5c 100644 --- a/http-routes/http-routes.go +++ b/http-routes/http-routes.go @@ -31,7 +31,7 @@ func wsEndpoint(w http.ResponseWriter, r *http.Request) { } func updateSessionEndpoint(w http.ResponseWriter, r *http.Request) { - var sessionToUpdate session.Session + var sessionToUpdate session.UpdateRequest var requestBody = r.Body enableCors(&w) err := json.NewDecoder(requestBody).Decode(&sessionToUpdate) diff --git a/session/session.go b/session/session.go index 4a80a01..bca59e0 100644 --- a/session/session.go +++ b/session/session.go @@ -48,11 +48,17 @@ type ExistingSessionReq struct { JoinSessionID string `json:"joinSession"` } +// UpdateRequest .. Incoming timer update from client (current driver) +type UpdateRequest struct { + SessionID string `json:"sessionId"` + UpdatedDuration int64 `json:"updatedDuration,omitempty"` +} + // Sessions is a collection of all current sessions var Sessions []Session // UpdateTimerChannel reads updates as they come in via updateSessionEndpoint -var UpdateTimerChannel = make(chan Session) +var UpdateTimerChannel = make(chan UpdateRequest) // CreateNewUserAndSession creates new users and sessions func CreateNewUserAndSession( @@ -97,8 +103,8 @@ func JoinExistingSession(joinExistingSessionData ExistingSessionReq, newUser Use } // HandleUpdateSession when a timer finishes -func HandleUpdateSession(sessionToUpdate Session) { - updatedSessionIdx, updateErr := sessionToUpdate.handleTimerEnd() +func HandleUpdateSession(sessionToUpdate UpdateRequest) { + updatedSessionIdx, updateErr := handleTimerEnd(sessionToUpdate) if updateErr != nil { log.Println("updateError", updateErr) return @@ -137,14 +143,19 @@ func RemoveSession(sessionID string) error { return nil } -func (session *Session) handleTimerEnd() (int, error) { - updatedSessionIdx, err := getExistingSession(session.SessionID) +// Map the incoming session request to an in-memory session +func handleTimerEnd(session UpdateRequest) (int, error) { + mappedSessionIdx, err := getExistingSession(session.SessionID) if err != nil { return -1, err } - Sessions[updatedSessionIdx].changeDriver() - Sessions[updatedSessionIdx].resetTimer() - return updatedSessionIdx, nil + // update duration + if session.UpdatedDuration > 0 { + Sessions[mappedSessionIdx].Duration = session.UpdatedDuration + } + Sessions[mappedSessionIdx].changeDriver() + Sessions[mappedSessionIdx].resetTimer() + return mappedSessionIdx, nil } func getExistingSession(desiredSessionID string) (int, error) { diff --git a/session/session_test.go b/session/session_test.go index a70c343..ca114a9 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -183,11 +183,15 @@ func TestHandleUpdateSession(t *testing.T) { JoinSessionID: sessionID, } testSession, _ := JoinExistingSession(sessionToJoin, newUser) + mockUpdateRequest := UpdateRequest{ + SessionID: testSession.SessionID, + UpdatedDuration: testSession.Duration, + } // mock broadcast to all sessionUsers mockConnInitUser.On("WriteJSON", &Sessions[sessionIndex]).Return(nil) mockConnJoiningUser.On("WriteJSON", &Sessions[sessionIndex]).Return(nil) // fire handle time end (changes driver and resets the timer) - HandleUpdateSession(testSession) + HandleUpdateSession(mockUpdateRequest) if Sessions[sessionIndex].CurrentDriver.UUID != newUser.UUID { t.Errorf("The Driver has not been correctly changed")