From eb56b5ddd9ea3a7f134cff124155db44ffd1c572 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 26 Sep 2021 04:25:06 +0000 Subject: [PATCH] Create limiters --- client/client.go | 10 ++++++++-- client/workspace.go | 5 +++-- client/workspaceclient.go | 5 +++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client/client.go b/client/client.go index d636a75..d436c39 100644 --- a/client/client.go +++ b/client/client.go @@ -11,7 +11,10 @@ import "os" import "github.com/firestuff/automana/headers" type Client struct { - client *http.Client + client *http.Client + rateLimit *RateLimit + concurrencyLimitRead *ConcurrencyLimit + concurrencyLimitWrite *ConcurrencyLimit } type errorDetails struct { @@ -34,7 +37,10 @@ type nextPage struct { func NewClient(token string) *Client { c := &Client{ - client: &http.Client{}, + client: &http.Client{}, + rateLimit: NewRateLimitPerMinute(1500, 1500), + concurrencyLimitRead: NewConcurrencyLimit(50), + concurrencyLimitWrite: NewConcurrencyLimit(15), } hdrs := headers.NewHeaders(c.client) diff --git a/client/workspace.go b/client/workspace.go index 421b1a7..142b655 100644 --- a/client/workspace.go +++ b/client/workspace.go @@ -20,8 +20,9 @@ func (c *Client) InWorkspace(name string) (*WorkspaceClient, error) { } return &WorkspaceClient{ - client: c, - workspace: wrk, + client: c, + workspace: wrk, + rateLimitSearch: NewRateLimitPerMinute(60, 60), }, nil } diff --git a/client/workspaceclient.go b/client/workspaceclient.go index 29138ed..a17cc88 100644 --- a/client/workspaceclient.go +++ b/client/workspaceclient.go @@ -1,6 +1,7 @@ package client type WorkspaceClient struct { - client *Client - workspace *Workspace + client *Client + workspace *Workspace + rateLimitSearch *RateLimit }