func handleRebalance()

in pkg/mock/spot/spot.go [107:132]


func handleRebalance(res http.ResponseWriter, req *http.Request) {
	requestTime := time.Now().Unix()
	if c.RebalanceTriggerTime != "" {
		triggerTime, _ := time.Parse(time.RFC3339, c.RebalanceTriggerTime)
		delayRemaining := triggerTime.Unix() - requestTime
		if delayRemaining > 0 {
			log.Printf("RebalanceTriggerTime %s was not reached yet. The rebalance rec will be available in %ds. Returning `notFoundResponse` for now", triggerTime, delayRemaining)
			server.ReturnNotFoundResponse(res)
			return
		}
	} else {
		delayInSeconds := c.RebalanceDelayInSec
		delayRemaining := delayInSeconds - (requestTime - spotItnStartTime)
		if delayRemaining > 0 {
			log.Printf("Delaying the response by %ds as requested. The rebalance rec will be available in %ds. Returning `notFoundResponse` for now", delayInSeconds, delayRemaining)
			server.ReturnNotFoundResponse(res)
			return
		}
	}
	// default time to requestTime, unless overridden
	mockResponseTime := time.Now().UTC().Format(time.RFC3339)
	if c.SpotConfig.RebalanceRecTime != "" {
		mockResponseTime = c.SpotConfig.RebalanceRecTime
	}
	server.FormatAndReturnJSONResponse(res, t.RebalanceRecommendationResponse{NoticeTime: mockResponseTime})
}