-
Notifications
You must be signed in to change notification settings - Fork 5
/
job_queue_redis.go
71 lines (54 loc) · 1.64 KB
/
job_queue_redis.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"time"
"github.com/go-redis/redis/v8"
log "github.com/sirupsen/logrus"
)
type jobQueueRedis struct {
redis *redis.Client
}
func (q jobQueueRedis) getJob(ctx context.Context) ([]string, error) {
result, err := q.redis.BLPop(ctx, 0*time.Second, "jobs").Result()
return result, err
}
func (q jobQueueRedis) setjobReceived(ctx context.Context, job benchJob) (int64, error) {
result, err := q.redis.RPush(ctx, job.ID, "received").Result()
if err != nil {
log.WithError(err).Error("Failed to set job status in queue")
}
if result < 1 {
log.Error("Failed to set job status in queue")
}
return result, err
}
func (q jobQueueRedis) setjobRunning(ctx context.Context, job benchJob) (int64, error) {
result, err := q.redis.RPush(ctx, job.ID, "running").Result()
if err != nil {
log.WithError(err).Error("Failed to set job status in queue")
}
if result < 1 {
log.Error("Failed to set job status in queue")
}
return result, err
}
func (q jobQueueRedis) setjobFailed(ctx context.Context, job benchJob) (int64, error) {
result, err := q.redis.RPush(ctx, job.ID, "failed").Result()
if err != nil {
log.WithError(err).Error("Failed to set job status in queue")
}
if result < 1 {
log.Error("Failed to set job status in queue")
}
return result, err
}
func (q jobQueueRedis) setjobResult(ctx context.Context, job benchJob, res agentExecRes) (int64, error) {
result, err := q.redis.RPush(ctx, job.ID, "done", res.StdOut, res.StdErr).Result()
if err != nil {
log.WithError(err).Error("Failed to set job status in queue")
}
if result < 1 {
log.Error("Failed to set job status in queue")
}
return result, err
}