Skip to content

Commit

Permalink
feat: Update Redis task keys and refactor AddLLMStormTask to use pend…
Browse files Browse the repository at this point in the history
…ing task queue
  • Loading branch information
Laisky committed Feb 5, 2025
1 parent 8927962 commit 286afad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
8 changes: 6 additions & 2 deletions library/db/redis/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const (
keyPrefix = "laisky/"
keyPrefixTask = keyPrefix + "tasks/"

// KeyPrefixTaskLLMStorm is the key prefix for LLM storm tasks
KeyPrefixTaskLLMStorm = keyPrefixTask + "llm_storm/"
// KeyTaskLLMStormPending is the key for LLM storm pending tasks
KeyTaskLLMStormPending = keyPrefixTask + "llm_storm/pending"
// KeyPrefixTaskLLMStormResult is the key prefix for LLM storm results
//
// `KeyPrefixTaskLLMStormResult + <task_id>`
KeyPrefixTaskLLMStormResult = keyPrefixTask + "llm_storm/result/"
)
15 changes: 2 additions & 13 deletions library/db/redis/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,17 @@ package redis

import (
"context"
"time"

"github.com/Laisky/errors/v2"
gutils "github.com/Laisky/go-utils/v5"
)

// AddLLMStormTask adds a new LLMStormTask to the queue
func (db *DB) AddLLMStormTask(ctx context.Context,
prompt string,
apiKey string,
) (taskID string, err error) {
taskID = gutils.UUID7()

task := &LLMStormTask{
TaskID: taskID,
CreatedAt: time.Now(),
Prompt: prompt,
APIKey: apiKey,
}

key := KeyPrefixTaskLLMStorm + task.TaskID
if err = db.db.RPush(ctx, key, task); err != nil {
task := NewLLMStormTask(prompt, apiKey)
if err = db.db.RPush(ctx, KeyTaskLLMStormPending, task); err != nil {
return taskID, errors.Wrap(err, "rpush")
}

Expand Down

0 comments on commit 286afad

Please sign in to comment.