mirror of https://github.com/dirtbags/moth.git
Mostly working, now
This commit is contained in:
parent
65788ceb04
commit
5d00d8df55
|
@ -97,6 +97,7 @@ func main() {
|
|||
|
||||
switch engine := *stateEngine; engine {
|
||||
case "redis":
|
||||
log.Println("Moth is running with Redis")
|
||||
redis_url_parsed := *redis_url
|
||||
if redis_url_parsed == "" {
|
||||
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)
|
||||
default:
|
||||
case "legacy":
|
||||
log.Println("Moth is running with the legacy state engine")
|
||||
state = NewState(afero.NewBasePathFs(osfs, *statePath))
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
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 {
|
||||
fmt.Println(err)
|
||||
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.
|
||||
func (s *RedisState) PointsLog() award.List {
|
||||
redis_args := &redis.ZRangeBy{
|
||||
Min: "0",
|
||||
Max: "-1",
|
||||
Min: "-inf",
|
||||
Max: "+inf",
|
||||
}
|
||||
scores, err := s.redis_client.ZRangeByScoreWithScores(s.ctx, s.formatRedisKey(REDIS_KEY_POINT_LOG), redis_args).Result()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Encountered an error processing points")
|
||||
return make(award.List, 0)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue