All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Add auth-svc /validate endpoint for token checking Add chat-svc with auth client and Redis task queue Add worker-svc chat handler for task processing Co-Authored-By: Claude Code <claude@anthropic.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// Package taskqueue provides a producer for pushing tasks to the worker queue.
|
|
package taskqueue
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.threesix.ai/jordan/sp4-debug-1770477266/pkg/logging"
|
|
"git.threesix.ai/jordan/sp4-debug-1770477266/pkg/queue"
|
|
)
|
|
|
|
// Job types that chat-svc produces for the worker.
|
|
const (
|
|
JobTypeChatProcess = "chat.process"
|
|
)
|
|
|
|
// Producer enqueues tasks for the worker-svc to process.
|
|
type Producer struct {
|
|
queue queue.Producer
|
|
logger *logging.Logger
|
|
}
|
|
|
|
// NewProducer creates a new task producer.
|
|
func NewProducer(q queue.Producer, logger *logging.Logger) *Producer {
|
|
return &Producer{
|
|
queue: q,
|
|
logger: logger.WithComponent("taskqueue"),
|
|
}
|
|
}
|
|
|
|
// EnqueueChatProcess enqueues a chat processing task for the worker.
|
|
func (p *Producer) EnqueueChatProcess(ctx context.Context, userID string, message string) (string, error) {
|
|
jobID, err := p.queue.Enqueue(ctx, JobTypeChatProcess, map[string]any{
|
|
"user_id": userID,
|
|
"message": message,
|
|
})
|
|
if err != nil {
|
|
return "", fmt.Errorf("enqueue chat.process: %w", err)
|
|
}
|
|
|
|
p.logger.Info("enqueued chat task", "job_id", jobID, "user_id", userID)
|
|
return jobID, nil
|
|
}
|