Use limits instead of periods
This commit is contained in:
@@ -70,7 +70,10 @@ func (c *Client) get(path string, values *url.Values, out interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.rateLimit.Acquire1()
|
||||||
|
c.concurrencyLimitRead.Acquire1()
|
||||||
resp, err := c.client.Do(req)
|
resp, err := c.client.Do(req)
|
||||||
|
c.concurrencyLimitRead.Release1()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -120,7 +123,10 @@ func (c *Client) doWithBody(method string, path string, body interface{}, out in
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.rateLimit.Acquire1()
|
||||||
|
c.concurrencyLimitWrite.Acquire1()
|
||||||
resp, err := c.client.Do(req)
|
resp, err := c.client.Do(req)
|
||||||
|
c.concurrencyLimitWrite.Release1()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ func (wc *WorkspaceClient) Search(q *SearchQuery) ([]*Task, error) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
resp := &tasksResponse{}
|
resp := &tasksResponse{}
|
||||||
|
wc.rateLimitSearch.Acquire1()
|
||||||
err := wc.client.get(path, values, resp)
|
err := wc.client.get(path, values, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package rules
|
|||||||
|
|
||||||
import "bytes"
|
import "bytes"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "math/rand"
|
|
||||||
import "strings"
|
import "strings"
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
@@ -28,6 +27,7 @@ type periodic struct {
|
|||||||
|
|
||||||
var periodics = []*periodic{}
|
var periodics = []*periodic{}
|
||||||
|
|
||||||
|
// TODO: Remove this, as it's now ignored
|
||||||
func EverySeconds(seconds int) *periodic {
|
func EverySeconds(seconds int) *periodic {
|
||||||
ret := &periodic{
|
ret := &periodic{
|
||||||
period: seconds,
|
period: seconds,
|
||||||
@@ -304,8 +304,6 @@ func (p *periodic) wait() {
|
|||||||
|
|
||||||
func (p *periodic) loop(client *client.Client) {
|
func (p *periodic) loop(client *client.Client) {
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Duration(rand.Intn(p.period)) * time.Second)
|
|
||||||
|
|
||||||
err := p.exec(client)
|
err := p.exec(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user