Files
geo/server/internal/tenant/app/template_assist_queue.go
T
root ce13331e26 feat(generation): migrate article generation and template-assist to RabbitMQ queues
Replace in-process generation with queue-based async execution via
RabbitMQ. Add generation task runtime for lifecycle management, article
generation payload/queue abstractions, and template-assist queue publisher.
Refactor prompt generation service to support batch generation with
per-item error tracking. Update stream hub to bridge queue events to SSE.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 14:20:26 +08:00

45 lines
1.1 KiB
Go

package app
import (
"context"
"encoding/json"
"fmt"
"github.com/geo-platform/tenant-api/internal/shared/messaging/rabbitmq"
)
func publishTemplateAssistTask(ctx context.Context, client *rabbitmq.Client, job assistJob) error {
if client == nil {
return fmt.Errorf("rabbitmq client is not configured")
}
payload, err := json.Marshal(job)
if err != nil {
return fmt.Errorf("marshal template assist job: %w", err)
}
if err := client.PublishTemplateAssistTask(ctx, payload); err != nil {
return fmt.Errorf("publish template assist task: %w", err)
}
return nil
}
func decodeTemplateAssistTask(payload []byte) (*assistJob, error) {
var job assistJob
if err := json.Unmarshal(payload, &job); err != nil {
return nil, fmt.Errorf("decode template assist job: %w", err)
}
if job.TaskID == "" || job.TaskType == "" || job.TenantID <= 0 || job.TemplateID <= 0 {
return nil, fmt.Errorf("template assist job is incomplete")
}
return &job, nil
}
func DecodeTemplateAssistTask(payload []byte) (*AssistJob, error) {
job, err := decodeTemplateAssistTask(payload)
if err != nil {
return nil, err
}
return job, nil
}