Skip to content

Commit

Permalink
fix: fixed from PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
codebender37 committed Dec 5, 2024
1 parent 080de18 commit b3db3b1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/seed/fixtures/fixture_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (o *FixtureService) CreateDefaultTask(ctx context.Context, title string, ex
db.Task.Type.Set(db.TaskTypeCodeGeneration),
db.Task.TaskData.Set(types.JSON(taskDataJSON)),
db.Task.Status.Set(db.TaskStatusInProgress),
db.Task.MaxResults.Set(10),
db.Task.MaxResults.Set(1),
db.Task.NumResults.Set(0),
db.Task.NumCriteria.Set(0),
db.Task.TotalReward.Set(101.0),
Expand Down
15 changes: 5 additions & 10 deletions cmd/seed/task_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
"max": 100,
"min": 1,
"type": "multi-score",
"options": [
"459520f8-b654-41a8-9f94-93e003c4ecb5",
"024ffca6-aac0-40d2-959b-1ab7b165b68e",
"4fa05b97-cd66-4df7-bb3a-298d2b04b148",
"1b26f82c-935f-432b-a60d-f21204e580f2"
]
"options": ["1", "2", "3", "4"]
}
],
"responses": [
{
"model": "459520f8-b654-41a8-9f94-93e003c4ecb5",
"model": "1",
"completion": {
"files": [
{
Expand All @@ -29,7 +24,7 @@
}
},
{
"model": "024ffca6-aac0-40d2-959b-1ab7b165b68e",
"model": "2",
"completion": {
"files": [
{
Expand All @@ -42,7 +37,7 @@
}
},
{
"model": "4fa05b97-cd66-4df7-bb3a-298d2b04b148",
"model": "3",
"completion": {
"files": [
{
Expand All @@ -55,7 +50,7 @@
}
},
{
"model": "1b26f82c-935f-432b-a60d-f21204e580f2",
"model": "4",
"completion": {
"files": [
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func getCallerIP(c *gin.Context) string {
// TODO - Need to check if this is the correct way without getting spoofing
if runtimeEnv := utils.LoadDotEnv("RUNTIME_ENV"); runtimeEnv == "aws" {
callerIp := c.Request.Header.Get("X-Original-Forwarded-For")
log.Trace().Msgf("Got caller IP from X-Original-Forwarded-For header: %s", callerIp)
log.Debug().Msgf("Got caller IP from X-Original-Forwarded-For header: %s", callerIp)
return callerIp
}
callerIp := c.ClientIP()
log.Trace().Msgf("Got caller IP from ClientIP: %s", callerIp)
log.Debug().Msgf("Got caller IP from ClientIP: %s", callerIp)
return callerIp
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const (
TasksByWorker CacheKey = "task:worker" // List of tasks by worker

// Task Result cache keys
TaskResultByTaskAndWorker CacheKey = "tr:task:worker" // Task result by task ID and worker ID
TaskResultByWorker CacheKey = "tr:worker" // Task results by worker ID
TaskResultByTaskAndWorker CacheKey = "tr:task:worker" // Task result by task ID and worker ID
TaskResultByWorker CacheKey = "tr:worker" // Task results by worker ID
TaskResultsTotal CacheKey = "metrics:task_results:total" // Total task results count

// Worker cache keys
WorkerByWallet CacheKey = "worker:wallet" // Worker by wallet address
Expand Down
12 changes: 7 additions & 5 deletions pkg/metric/metrics_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ func (metricService *MetricService) UpdateCompletedTaskCount(ctx context.Context
}

func (metricService *MetricService) UpdateTotalTaskResultsCount(ctx context.Context) error {
cache := cache.GetCacheInstance()
cacheInstance := cache.GetCacheInstance()
metricORM := orm.NewMetricsORM()

cacheKey := "metrics:task_results:total"
cacheKey := string(cache.TaskResultsTotal)

// Try to get current count from Redis
_, err := cache.Redis.Get(ctx, cacheKey).Int64()
currentCount, err := cacheInstance.Redis.Get(ctx, cacheKey).Int64()
log.Info().Int64("CurrentCount", currentCount).Msg("Current count")
if err == redis.Nil { // Key doesn't exist (e.g., after Redis restart)
// Get the last metric from database
lastMetric, err := metricORM.GetMetricsDataByMetricType(ctx, db.MetricsTypeTotalNumTaskResults)
log.Info().Interface("LastMetric", lastMetric).Msg("Last metric")
if err != nil && !db.IsErrNotFound(err) {
return err
}
Expand All @@ -78,7 +80,7 @@ func (metricService *MetricService) UpdateTotalTaskResultsCount(ctx context.Cont
}
currentCount := int64(lastMetricData.TotalNumTasksResults)
// Set the Redis counter to last known value
if err := cache.Redis.Set(ctx, cacheKey, currentCount, 0).Err(); err != nil {
if err := cacheInstance.Redis.Set(ctx, cacheKey, currentCount, 0).Err(); err != nil {
return err
}
}
Expand All @@ -87,7 +89,7 @@ func (metricService *MetricService) UpdateTotalTaskResultsCount(ctx context.Cont
}

// Increment the counter
count, err := cache.Redis.Incr(ctx, cacheKey).Result()
count, err := cacheInstance.Redis.Incr(ctx, cacheKey).Result()
if err != nil {
log.Error().Err(err).Msg("Failed to increment task results count")
return err
Expand Down

0 comments on commit b3db3b1

Please sign in to comment.