feat(generation): resume manual summary jobs
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -31,6 +32,28 @@ func (r *Repository) SaveGeneration(ctx context.Context, userID, id string, summ
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO summary_generations (id,user_id,summary_id,outcome,created_at) VALUES ($1,$2,$3,$4,$5)`, id, userID, summaryID, string(outcome), createdAt); err != nil {
|
||||
return err
|
||||
}
|
||||
// HTTP jobs complete atomically with their summary/outcome. Scheduled runs
|
||||
// retain the existing persistence path and do not require a job row.
|
||||
if GenerationJobID(ctx) != "" {
|
||||
var terminal struct {
|
||||
Status string `json:"status"`
|
||||
FailureCode string `json:"failure_code"`
|
||||
}
|
||||
if err = json.Unmarshal(outcome, &terminal); err != nil {
|
||||
return err
|
||||
}
|
||||
result, updateErr := tx.ExecContext(ctx, `UPDATE summary_generation_jobs SET status=$3,failure_code=$4,finished_at=NOW() WHERE id=$1 AND user_id=$2 AND status='running'`, id, userID, terminal.Status, terminal.FailureCode)
|
||||
if updateErr != nil {
|
||||
return updateErr
|
||||
}
|
||||
n, updateErr := result.RowsAffected()
|
||||
if updateErr != nil {
|
||||
return updateErr
|
||||
}
|
||||
if n != 1 {
|
||||
return fmt.Errorf("generation job is no longer running")
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
func (r *Repository) ListGenerations(ctx context.Context, userID string, limit int) ([]GenerationHistory, error) {
|
||||
|
||||
Reference in New Issue
Block a user