// Package jobqueue provides an adapter for enqueuing async tasks. package jobqueue import ( "context" "fmt" "git.threesix.ai/jordan/sp4-v2-1770499323/pkg/queue" "git.threesix.ai/jordan/sp4-v2-1770499323/services/chat-svc/internal/port" ) // compile-time check var _ port.TaskProducer = (*Producer)(nil) // Producer enqueues chat tasks to the job queue. type Producer struct { queue queue.Producer } // New creates a new task producer. func New(q queue.Producer) *Producer { return &Producer{queue: q} } // EnqueueTask enqueues a chat_task job with the given action and payload. func (p *Producer) EnqueueTask(ctx context.Context, action string, payload map[string]any) (string, error) { if payload == nil { payload = make(map[string]any) } payload["action"] = action jobID, err := p.queue.Enqueue(ctx, "chat_task", payload) if err != nil { return "", fmt.Errorf("enqueue chat task: %w", err) } return jobID, nil }