forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
event.go
42 lines (33 loc) · 899 Bytes
/
event.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
package dtrack
import (
"context"
"fmt"
"net/http"
)
type EventService struct {
client *Client
}
type EventToken string
type EventTokenResponse struct {
Token EventToken `json:"token"`
}
type eventProcessingResponse struct {
Processing bool `json:"processing"`
}
// IsBeingProcessed checks whether the event associated with a given token is still being processed.
func (es EventService) IsBeingProcessed(ctx context.Context, token EventToken) (bool, error) {
err := es.client.assertServerVersionAtLeast("4.11.0")
if err != nil {
return false, err
}
req, err := es.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/event/token/%s", token))
if err != nil {
return false, err
}
var processingResponse eventProcessingResponse
_, err = es.client.doRequest(req, &processingResponse)
if err != nil {
return false, err
}
return processingResponse.Processing, nil
}