Mostly working, now

This commit is contained in:
Donaldson 2021-12-10 16:13:34 -08:00
parent 65788ceb04
commit 5d00d8df55
2 changed files with 13 additions and 3 deletions

View File

@ -97,6 +97,7 @@ func main() {
switch engine := *stateEngine; engine { switch engine := *stateEngine; engine {
case "redis": case "redis":
log.Println("Moth is running with Redis")
redis_url_parsed := *redis_url redis_url_parsed := *redis_url
if redis_url_parsed == "" { if redis_url_parsed == "" {
redis_url_parsed = os.Getenv("REDIS_URL") redis_url_parsed = os.Getenv("REDIS_URL")
@ -126,6 +127,7 @@ func main() {
state = NewRedisState(redis_url_parsed, int(redis_db_parsed), redis_instance_id_parsed) state = NewRedisState(redis_url_parsed, int(redis_db_parsed), redis_instance_id_parsed)
default: default:
case "legacy": case "legacy":
log.Println("Moth is running with the legacy state engine")
state = NewState(afero.NewBasePathFs(osfs, *statePath)) state = NewState(afero.NewBasePathFs(osfs, *statePath))
} }

View File

@ -131,9 +131,16 @@ func (s *RedisState) SetTeamName(teamID, teamName string) error {
return fmt.Errorf("team ID: (%s) not found in list of valid team IDs", teamID) return fmt.Errorf("team ID: (%s) not found in list of valid team IDs", teamID)
} }
success, err := s.redis_client.HSetNX(s.ctx, s.formatRedisKey(REDIS_KEY_TEAM_IDS), teamID, teamName).Result() exists, err := s.redis_client.HExists(s.ctx, s.formatRedisKey(REDIS_KEY_TEAMS), teamID).Result()
if exists {
return nil
}
success, err := s.redis_client.HSetNX(s.ctx, s.formatRedisKey(REDIS_KEY_TEAMS), teamID, teamName).Result()
if err != nil { if err != nil {
fmt.Println(err)
return fmt.Errorf("Unexpected error while setting team ID: %s and team Name: %s", teamID, teamName) return fmt.Errorf("Unexpected error while setting team ID: %s and team Name: %s", teamID, teamName)
} }
@ -148,12 +155,13 @@ func (s *RedisState) SetTeamName(teamID, teamName string) error {
// PointsLog retrieves the current points log. // PointsLog retrieves the current points log.
func (s *RedisState) PointsLog() award.List { func (s *RedisState) PointsLog() award.List {
redis_args := &redis.ZRangeBy{ redis_args := &redis.ZRangeBy{
Min: "0", Min: "-inf",
Max: "-1", Max: "+inf",
} }
scores, err := s.redis_client.ZRangeByScoreWithScores(s.ctx, s.formatRedisKey(REDIS_KEY_POINT_LOG), redis_args).Result() scores, err := s.redis_client.ZRangeByScoreWithScores(s.ctx, s.formatRedisKey(REDIS_KEY_POINT_LOG), redis_args).Result()
if err != nil { if err != nil {
fmt.Println("Encountered an error processing points")
return make(award.List, 0) return make(award.List, 0)
} }