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