-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathclient.go
48 lines (41 loc) · 1.09 KB
/
client.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
package client
import (
"context"
"github.com/content-services/content-sources-backend/pkg/tasks"
"github.com/content-services/content-sources-backend/pkg/tasks/queue"
"github.com/google/uuid"
)
//go:generate $GO_OUTPUT/mockery --name TaskClient --filename client_mock.go --inpackage
type TaskClient interface {
Enqueue(task queue.Task) (uuid.UUID, error)
SendCancelNotification(ctx context.Context, taskId string) error
}
type Client struct {
queue queue.Queue
}
func NewTaskClient(q queue.Queue) TaskClient {
return &Client{
queue: q,
}
}
// TODO propgate context to enqueue
func (c *Client) Enqueue(task queue.Task) (uuid.UUID, error) {
id, err := c.queue.Enqueue(&task)
if err != nil {
return uuid.Nil, err
}
logger := tasks.LogForTask(id.String(), task.Typename, task.RequestID)
logger.Info().Msg("[Enqueued Task]")
return id, nil
}
func (c *Client) SendCancelNotification(ctx context.Context, taskId string) error {
taskUUID, err := uuid.Parse(taskId)
if err != nil {
return err
}
err = c.queue.SendCancelNotification(ctx, taskUUID)
if err != nil {
return err
}
return nil
}