change ignore fresh updated, do update after merge instead.
This commit is contained in:
parent
fed315367a
commit
ed7810cded
3 changed files with 54 additions and 27 deletions
|
|
@ -221,6 +221,16 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
||||||
if currentConfig != requestedConfig {
|
if currentConfig != requestedConfig {
|
||||||
d.taoLogger.Log.Debug("GetRecipe", zap.Any("ActualFileNotMatch", "Skip this!"))
|
d.taoLogger.Log.Debug("GetRecipe", zap.Any("ActualFileNotMatch", "Skip this!"))
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// detect patches, return original
|
||||||
|
var cached_original_recipe models.Recipe
|
||||||
|
err := d.redisClient.GetKeyTo(filename, &cached_original_recipe)
|
||||||
|
|
||||||
|
if err == nil && d.redisClient.HealthCheck() == nil {
|
||||||
|
d.taoLogger.Log.Debug("GetRecipe.NoReturnUpdated", zap.Any("target", filename))
|
||||||
|
return &cached_original_recipe
|
||||||
|
}
|
||||||
|
|
||||||
// if equal, OK
|
// if equal, OK
|
||||||
return d.CurrentRecipe[countryID]
|
return d.CurrentRecipe[countryID]
|
||||||
}
|
}
|
||||||
|
|
@ -239,6 +249,19 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
||||||
if currentConfig != requestedConfig {
|
if currentConfig != requestedConfig {
|
||||||
d.taoLogger.Log.Debug("GetRecipe", zap.Any("InvalidOnStored", "Skip this!"))
|
d.taoLogger.Log.Debug("GetRecipe", zap.Any("InvalidOnStored", "Skip this!"))
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// detect patches, return original
|
||||||
|
|
||||||
|
var cached_original_recipe models.Recipe
|
||||||
|
err := d.redisClient.GetKeyTo(filename, &cached_original_recipe)
|
||||||
|
|
||||||
|
if err == nil && d.redisClient.HealthCheck() == nil {
|
||||||
|
d.taoLogger.Log.Debug("GetRecipe.NoReturnUpdated", zap.Any("target", filename))
|
||||||
|
return &cached_original_recipe
|
||||||
|
}
|
||||||
|
|
||||||
|
d.taoLogger.Log.Debug("GetRecipe.ReturnDefault", zap.Any("error_cache_recipe", err))
|
||||||
|
|
||||||
// if equal, OK
|
// if equal, OK
|
||||||
return recipe.Recipe[countryID]
|
return recipe.Recipe[countryID]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -448,6 +448,8 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
||||||
// Apply changes
|
// Apply changes
|
||||||
tempRecipe := models.Recipe01{}
|
tempRecipe := models.Recipe01{}
|
||||||
tempRecipe = tempRecipe.FromMap(changeMap)
|
tempRecipe = tempRecipe.FromMap(changeMap)
|
||||||
|
|
||||||
|
// Disable temp! Was updated the master by patch. Too fast
|
||||||
rr.data.SetValuesToRecipe(targetRecipe.Recipe01, tempRecipe)
|
rr.data.SetValuesToRecipe(targetRecipe.Recipe01, tempRecipe)
|
||||||
|
|
||||||
rr.taoLogger.Log.Debug("ApplyChange", zap.Any("status", "passed"))
|
rr.taoLogger.Log.Debug("ApplyChange", zap.Any("status", "passed"))
|
||||||
|
|
@ -502,36 +504,35 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// this following codes do need users to pass update to each other
|
// this following codes do need users to pass update to each other
|
||||||
// otherwise, the changes will diverge
|
// otherwise, the changes will diverge
|
||||||
|
|
||||||
file, _ := os.Create(temp_file_name)
|
file, _ := os.Create(temp_file_name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when tried to create file")))
|
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when tried to create file")))
|
||||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// write to local if cannot connect
|
// write to local if cannot connect
|
||||||
encoder := json.NewEncoder(file)
|
encoder := json.NewEncoder(file)
|
||||||
encoder.SetIndent("", " ")
|
encoder.SetIndent("", " ")
|
||||||
// full
|
// full
|
||||||
err = encoder.Encode(targetRecipe)
|
err = encoder.Encode(tempRecipe)
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
// partial
|
// partial
|
||||||
// err = encoder.Encode(changes)
|
// err = encoder.Encode(changes)
|
||||||
|
|
||||||
// put changes to redis
|
// put changes to redis
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when write file")))
|
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when write file")))
|
||||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to commit
|
// add to commit
|
||||||
|
|
@ -624,7 +625,7 @@ func (rr *RecipeRouter) getSavedAsPatches(w http.ResponseWriter, r *http.Request
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("targetPatchOf", countryID+"."+filename+":patchList"), zap.Any("patchList", patchList))
|
// rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("targetPatchOf", countryID+"."+filename+":patchList"), zap.Any("patchList", patchList))
|
||||||
|
|
||||||
// find patch content from patch list
|
// find patch content from patch list
|
||||||
keys, err := rr.cache_db.KeyList()
|
keys, err := rr.cache_db.KeyList()
|
||||||
|
|
@ -662,7 +663,11 @@ func (rr *RecipeRouter) getSavedAsPatches(w http.ResponseWriter, r *http.Request
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(patchMap)
|
json.NewEncoder(w).Encode(patchMap)
|
||||||
|
|
||||||
rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("patchMap", patchMap))
|
// The above code is using the Zap logging library in Go to log a debug message with two fields. The
|
||||||
|
// first field is "targetPatchOf" with the value of countryID + "." + filename + ":patchList", and the
|
||||||
|
// second field is "patchList" with the value of the variable patchList. This log message is related
|
||||||
|
// to the "RecipeRouter.getSavedAsPatches" method.
|
||||||
|
// rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("patchMap", patchMap))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RecipeRouter) getToppings(w http.ResponseWriter, r *http.Request) {
|
func (rr *RecipeRouter) getToppings(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"recipe-manager/data"
|
"recipe-manager/data"
|
||||||
"recipe-manager/services/logger"
|
"recipe-manager/services/logger"
|
||||||
|
|
@ -28,7 +27,7 @@ func NewToppingRouter(data *data.Data, taoLogger *logger.TaoLogger) *ToppingRout
|
||||||
func (tr *ToppingRouter) Route(r chi.Router) {
|
func (tr *ToppingRouter) Route(r chi.Router) {
|
||||||
|
|
||||||
// check incoming request
|
// check incoming request
|
||||||
fmt.Println("topping router", r.Routes())
|
// fmt.Println("topping router", r.Routes())
|
||||||
|
|
||||||
r.Route("/toppover", func(r chi.Router) {
|
r.Route("/toppover", func(r chi.Router) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue