2020-09-10 10:11:34 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Meta interface {
|
|
|
|
Get(requestID string) (*Request, error)
|
|
|
|
CreateRequest(requestID string, headers http.Header, uri string, method string) error
|
|
|
|
AddAttempt(requestID, attemptID string, header AttemptHeader) (*Request, error)
|
|
|
|
Complete(requestID string) error
|
|
|
|
Iterate(handler func(id string, record Request) error) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type AttemptHeader struct {
|
2020-10-10 09:52:11 +00:00
|
|
|
Code int `json:"code"`
|
|
|
|
Headers http.Header `json:"headers"`
|
|
|
|
StartedAt time.Time `json:"started_at"`
|
2020-09-10 10:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Attempt struct {
|
|
|
|
AttemptHeader
|
|
|
|
ID string `json:"id"`
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Request struct {
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
CompleteAt time.Time `json:"complete_at,omitempty"`
|
|
|
|
Attempts []Attempt `json:"attempts"`
|
|
|
|
Headers http.Header `json:"headers"`
|
|
|
|
URI string `json:"uri"`
|
|
|
|
Method string `json:"method"`
|
|
|
|
Complete bool `json:"complete"`
|
|
|
|
}
|
2020-11-09 17:57:57 +00:00
|
|
|
|
|
|
|
func (rq *Request) Success() bool {
|
|
|
|
for _, item := range rq.Attempts {
|
|
|
|
if item.Code == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|