-
Notifications
You must be signed in to change notification settings - Fork 127
/
getjobrunerror.go
44 lines (38 loc) · 1.27 KB
/
getjobrunerror.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package repository
import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/armadaproject/armada/internal/common/armadacontext"
"github.com/armadaproject/armada/internal/common/compress"
)
type GetJobRunErrorRepository interface {
GetJobRunError(ctx *armadacontext.Context, runId string) (string, error)
}
type SqlGetJobRunErrorRepository struct {
db *pgxpool.Pool
decompressor compress.Decompressor
}
func NewSqlGetJobRunErrorRepository(db *pgxpool.Pool, decompressor compress.Decompressor) *SqlGetJobRunErrorRepository {
return &SqlGetJobRunErrorRepository{
db: db,
decompressor: decompressor,
}
}
func (r *SqlGetJobRunErrorRepository) GetJobRunError(ctx *armadacontext.Context, runId string) (string, error) {
var rawBytes []byte
err := r.db.QueryRow(ctx, "SELECT error FROM job_run WHERE run_id = $1 AND error IS NOT NULL", runId).Scan(&rawBytes)
if err != nil {
if err == pgx.ErrNoRows {
return "", errors.Errorf("no error found for run with id %s", runId)
}
return "", err
}
decompressed, err := r.decompressor.Decompress(rawBytes)
if err != nil {
log.WithError(err).Error("failed to decompress")
return "", err
}
return string(decompressed), nil
}