Create limiters

This commit is contained in:
Ian Gulliver
2021-09-26 04:25:06 +00:00
parent 1846eb45bc
commit eb56b5ddd9
3 changed files with 14 additions and 6 deletions

View File

@@ -11,7 +11,10 @@ import "os"
import "github.com/firestuff/automana/headers" import "github.com/firestuff/automana/headers"
type Client struct { type Client struct {
client *http.Client client *http.Client
rateLimit *RateLimit
concurrencyLimitRead *ConcurrencyLimit
concurrencyLimitWrite *ConcurrencyLimit
} }
type errorDetails struct { type errorDetails struct {
@@ -34,7 +37,10 @@ type nextPage struct {
func NewClient(token string) *Client { func NewClient(token string) *Client {
c := &Client{ c := &Client{
client: &http.Client{}, client: &http.Client{},
rateLimit: NewRateLimitPerMinute(1500, 1500),
concurrencyLimitRead: NewConcurrencyLimit(50),
concurrencyLimitWrite: NewConcurrencyLimit(15),
} }
hdrs := headers.NewHeaders(c.client) hdrs := headers.NewHeaders(c.client)

View File

@@ -20,8 +20,9 @@ func (c *Client) InWorkspace(name string) (*WorkspaceClient, error) {
} }
return &WorkspaceClient{ return &WorkspaceClient{
client: c, client: c,
workspace: wrk, workspace: wrk,
rateLimitSearch: NewRateLimitPerMinute(60, 60),
}, nil }, nil
} }

View File

@@ -1,6 +1,7 @@
package client package client
type WorkspaceClient struct { type WorkspaceClient struct {
client *Client client *Client
workspace *Workspace workspace *Workspace
rateLimitSearch *RateLimit
} }