update recipe list and disable git pulling
This commit is contained in:
parent
15e74d47e3
commit
fea5f8452a
7 changed files with 171 additions and 133 deletions
|
|
@ -3,6 +3,7 @@ package data
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"recipe-manager/helpers"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/services/logger"
|
||||
|
|
@ -47,7 +48,11 @@ func NewData() *Data {
|
|||
|
||||
defaultFile := "coffeethai02_580.json"
|
||||
defaultCountry := "thai"
|
||||
defaultRecipe := helpers.ReadRecipeFile(defaultCountry, defaultFile)
|
||||
defaultRecipe, err := helpers.ReadRecipeFile(defaultCountry, defaultFile)
|
||||
|
||||
if err != nil {
|
||||
log.Panic("Error when read default recipe file:", err)
|
||||
}
|
||||
|
||||
return &Data{
|
||||
CurrentFile: defaultFile,
|
||||
|
|
@ -83,7 +88,14 @@ func (d *Data) GetRecipe(countryID, filename string) models.Recipe {
|
|||
// change current version and read new recipe
|
||||
d.CurrentFile = filename
|
||||
d.CurrentCountryID = countryID
|
||||
d.currentRecipe = helpers.ReadRecipeFile(countryID, filename)
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
logger.GetInstance().Error("Error when read recipe file", zap.Error(err))
|
||||
return *d.currentRecipe
|
||||
}
|
||||
|
||||
d.currentRecipe = recipe
|
||||
|
||||
// save to map
|
||||
if len(d.recipeMap) > 5 { // limit keep in memory 5 version
|
||||
|
|
@ -154,7 +166,15 @@ func (d *Data) GetMaterialSetting(countryID, filename string) []models.MaterialS
|
|||
|
||||
d.CurrentFile = filename
|
||||
d.CurrentCountryID = countryID
|
||||
d.currentRecipe = helpers.ReadRecipeFile(countryID, filename)
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
logger.GetInstance().Error("Error when read recipe file", zap.Error(err))
|
||||
copy(result, d.currentRecipe.MaterialSetting)
|
||||
return result
|
||||
}
|
||||
|
||||
d.currentRecipe = recipe
|
||||
|
||||
// save to map
|
||||
if len(d.recipeMap) > 5 { // limit keep in memory 5 version
|
||||
|
|
@ -190,7 +210,14 @@ func (d *Data) GetMaterialCode(ids []uint64, countryID, filename string) []model
|
|||
} else {
|
||||
d.CurrentFile = filename
|
||||
d.CurrentCountryID = countryID
|
||||
d.currentRecipe = helpers.ReadRecipeFile(countryID, filename)
|
||||
recipe, err := helpers.ReadRecipeFile(countryID, filename)
|
||||
|
||||
if err != nil {
|
||||
logger.GetInstance().Error("Error when read recipe file", zap.Error(err))
|
||||
return d.currentRecipe.MaterialCode
|
||||
}
|
||||
|
||||
d.currentRecipe = recipe
|
||||
|
||||
// save to map
|
||||
if len(d.recipeMap) > 5 { // limit keep in memory 5 version
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package helpers
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
|
@ -29,7 +30,7 @@ func ReadFile(filePath string) (string, error) {
|
|||
return string(file), nil
|
||||
}
|
||||
|
||||
func ReadRecipeFile(countryID, filePath string) *models.Recipe {
|
||||
func ReadRecipeFile(countryID, filePath string) (*models.Recipe, error) {
|
||||
|
||||
if countryID == "thai" {
|
||||
countryID = ""
|
||||
|
|
@ -38,8 +39,7 @@ func ReadRecipeFile(countryID, filePath string) *models.Recipe {
|
|||
file, err := os.Open(path.Join("cofffeemachineConfig", countryID, filePath))
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error when open file: %s", err)
|
||||
return nil
|
||||
return nil, fmt.Errorf("error when open file: %s", err)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
|
@ -49,11 +49,10 @@ func ReadRecipeFile(countryID, filePath string) *models.Recipe {
|
|||
err = json.NewDecoder(file).Decode(&data)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error when decode file: %s", err)
|
||||
return nil
|
||||
return nil, fmt.Errorf("error when decode file: %s", err)
|
||||
}
|
||||
|
||||
return data
|
||||
return data, nil
|
||||
}
|
||||
|
||||
type RecipePath struct {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func main() {
|
|||
}()
|
||||
|
||||
// Spawn a goroutine to run git pull every 10 minutes
|
||||
go RunGitRecipeWorker()
|
||||
//go RunGitRecipeWorker()
|
||||
|
||||
err := s.Run()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue