Skip to content

Commit

Permalink
Merge pull request #128 from zhenghaoz/dev
Browse files Browse the repository at this point in the history
gorse v0.2.0-rc1
  • Loading branch information
zhenghaoz committed May 2, 2021
2 parents 8d947c5 + e9e441e commit 784ad6b
Show file tree
Hide file tree
Showing 48 changed files with 1,008 additions and 708 deletions.
10 changes: 7 additions & 3 deletions base/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ import (
var logger *zap.Logger

func init() {
logger, _ = zap.NewProduction()
SetProductionLogger()
}

func Logger() *zap.Logger {
return logger
}

func SetLogger(_logger *zap.Logger) {
logger = _logger
func SetProductionLogger() {
logger, _ = zap.NewProduction()
}

func SetDevelopmentLogger() {
logger, _ = zap.NewDevelopment()
}

// Max finds the maximum in a vector of integers. Panic if the slice is empty.
Expand Down
156 changes: 0 additions & 156 deletions cmd/gorse-cli/export.go

This file was deleted.

6 changes: 6 additions & 0 deletions cmd/gorse-master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var masterCommand = &cobra.Command{
fmt.Println(version.Name)
return
}
// setup logger
debugMode, _ := cmd.PersistentFlags().GetBool("debug")
if debugMode {
base.SetDevelopmentLogger()
}
// Start master
configPath, _ := cmd.PersistentFlags().GetString("config")
base.Logger().Info("load config", zap.String("config", configPath))
Expand All @@ -45,6 +50,7 @@ var masterCommand = &cobra.Command{
}

func init() {
masterCommand.PersistentFlags().Bool("debug", false, "use debug log mode")
masterCommand.PersistentFlags().StringP("config", "c", "/etc/gorse.toml", "configuration file path")
masterCommand.PersistentFlags().BoolP("version", "v", false, "gorse version")
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/gorse-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var serverCommand = &cobra.Command{
fmt.Println(version.Name)
return
}
// setup logger
debugMode, _ := cmd.PersistentFlags().GetBool("debug")
if debugMode {
base.SetDevelopmentLogger()
}
// start server
masterPort, _ := cmd.PersistentFlags().GetInt("master-port")
masterHost, _ := cmd.PersistentFlags().GetString("master-host")
Expand All @@ -48,6 +53,7 @@ func init() {
serverCommand.PersistentFlags().String("master-host", "127.0.0.1", "host of master node")
serverCommand.PersistentFlags().Int("http-port", 8087, "port of RESTful API")
serverCommand.PersistentFlags().String("http-host", "127.0.0.1", "host of RESTful API")
serverCommand.PersistentFlags().Bool("debug", false, "use debug log mode")
}

func main() {
Expand Down
6 changes: 6 additions & 0 deletions cmd/gorse-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ var workerCommand = &cobra.Command{
masterPort, _ := cmd.PersistentFlags().GetInt("master-port")
httpHost, _ := cmd.PersistentFlags().GetString("http-host")
httpPort, _ := cmd.PersistentFlags().GetInt("http-port")
debugMode, _ := cmd.PersistentFlags().GetBool("debug")
workingJobs, _ := cmd.PersistentFlags().GetInt("jobs")
// setup logger
if debugMode {
base.SetDevelopmentLogger()
}
// create worker
w := worker.NewWorker(masterHost, masterPort, httpHost, httpPort, workingJobs)
w.Serve()
Expand All @@ -40,6 +45,7 @@ func init() {
workerCommand.PersistentFlags().Int("master-port", 8086, "port of master node")
workerCommand.PersistentFlags().String("http-host", "127.0.0.1", "host of status report")
workerCommand.PersistentFlags().Int("http-port", 8089, "port of status report")
workerCommand.PersistentFlags().Bool("debug", false, "use debug log mode")
workerCommand.PersistentFlags().IntP("jobs", "j", 1, "number of working jobs.")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

const Name = "0.2.0-rc0"
const Name = "0.2.0-rc1"
30 changes: 19 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 gorse Project Authors
// Copyright 2021 gorse Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package config

import (
Expand Down Expand Up @@ -45,6 +46,8 @@ type DatabaseConfig struct {
AutoInsertItem bool `toml:"auto_insert_item"` // insert new items while inserting feedback
CacheSize int `toml:"cache_size"` // cache size for intermediate recommendation
PositiveFeedbackType []string `toml:"positive_feedback_types"` // positive feedback type
PositiveFeedbackTTL uint `toml:"positive_feedback_ttl"`
ItemTTL uint `toml:"item_ttl"`
}

// LoadDefaultIfNil loads default settings if config is nil.
Expand Down Expand Up @@ -87,22 +90,24 @@ func (config *MasterConfig) LoadDefaultIfNil() *MasterConfig {
}

type RecommendConfig struct {
PopularWindow int `toml:"popular_window"`
FitPeriod int `toml:"fit_period"`
SearchPeriod int `toml:"search_period"`
SearchEpoch int `toml:"search_epoch"`
SearchTrials int `toml:"search_trials"`
PopularWindow int `toml:"popular_window"`
FitPeriod int `toml:"fit_period"`
MaxRecommendPeriod int `toml:"max_recommend_period"`
SearchPeriod int `toml:"search_period"`
SearchEpoch int `toml:"search_epoch"`
SearchTrials int `toml:"search_trials"`
}

// LoadDefaultIfNil loads default settings if config is nil.
func (config *RecommendConfig) LoadDefaultIfNil() *RecommendConfig {
if config == nil {
return &RecommendConfig{
PopularWindow: 1,
FitPeriod: 60,
SearchPeriod: 60,
SearchEpoch: 100,
SearchTrials: 10,
PopularWindow: 1,
FitPeriod: 60,
MaxRecommendPeriod: 1,
SearchPeriod: 60,
SearchEpoch: 100,
SearchTrials: 10,
}
}
return config
Expand Down Expand Up @@ -177,6 +182,9 @@ func (config *Config) FillDefault(meta toml.MetaData) {
if !meta.IsDefined("recommend", "fit_period") {
config.Recommend.FitPeriod = defaultRecommendConfig.FitPeriod
}
if !meta.IsDefined("recommend", "max_recommend_period") {
config.Recommend.MaxRecommendPeriod = defaultRecommendConfig.MaxRecommendPeriod
}
if !meta.IsDefined("recommend", "search_period") {
config.Recommend.SearchPeriod = defaultRecommendConfig.SearchPeriod
}
Expand Down
7 changes: 6 additions & 1 deletion config/config.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ auto_insert_user = true
auto_insert_item = false
# types of positive feedback
positive_feedback_types = ["star"]
# positive feedback time-to-live (days), 0 means disabled.
positive_feedback_ttl = 0
# item time-to-live (days), 0 means disabled.
item_ttl = 0

# This section declares settings for the master node.
[master]
Expand All @@ -19,7 +23,7 @@ http_port = 8088 # HTTP API port
http_host = "127.0.0.1" # HTTP API host
search_jobs = 1 # number of jobs for model search
fit_jobs = 1 # number of jobs for model fitting
meta_timeout = 30 # cluster meta timeout (second)
meta_timeout = 10 # cluster meta timeout (second)

# This section declares settings for the server node.
[server]
Expand All @@ -31,3 +35,4 @@ api_key = "" # secret key for RESTful APIs (SSL required)
popular_window = 365 # timw window of popular items (days)
fit_period = 10 # time period for model fitting (minutes)
search_period = 60 # time period for model searching (minutes)
max_recommend_period = 1 # time period for inactive user recommendation (days)
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestLoadConfig(t *testing.T) {
assert.Equal(t, true, config.Database.AutoInsertUser)
assert.Equal(t, false, config.Database.AutoInsertItem)
assert.Equal(t, []string{"star", "fork"}, config.Database.PositiveFeedbackType)
assert.Equal(t, uint(998), config.Database.PositiveFeedbackTTL)
assert.Equal(t, uint(999), config.Database.ItemTTL)

// master configuration
assert.Equal(t, 8086, config.Master.Port)
Expand Down
20 changes: 0 additions & 20 deletions docker/ardb/Dockerfile

This file was deleted.

0 comments on commit 784ad6b

Please sign in to comment.