fix: fixed the MRPS.
This commit is contained in:
parent
d7e751677f
commit
546600a027
4 changed files with 37 additions and 14 deletions
16
api/api.go
16
api/api.go
|
@ -40,7 +40,7 @@ type Client struct {
|
|||
mrps int
|
||||
|
||||
ticker *time.Ticker
|
||||
req chan struct{}
|
||||
req, reqNeed chan struct{}
|
||||
|
||||
requestsMade int64
|
||||
}
|
||||
|
@ -125,16 +125,16 @@ func NewAPI(secretPath string) (*Client, error) {
|
|||
func (client *Client) SetMRPS(rps int) *Client {
|
||||
client.mrps = rps
|
||||
client.req = make(chan struct{})
|
||||
client.ticker = time.NewTicker(time.Second)
|
||||
client.reqNeed = make(chan struct{})
|
||||
client.ticker = time.NewTicker(
|
||||
time.Second/time.Duration(rps),
|
||||
)
|
||||
go func() {
|
||||
for {
|
||||
for _ = range make(
|
||||
[]struct{},
|
||||
client.mrps - client.availableRequests,
|
||||
) {
|
||||
select {
|
||||
case <- client.reqNeed :
|
||||
client.req <- struct{}{}
|
||||
}
|
||||
client.availableRequests = client.mrps
|
||||
<-client.ticker.C
|
||||
}
|
||||
}()
|
||||
|
@ -147,8 +147,8 @@ func (client *Client) waitInQueue() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
client.reqNeed <- struct{}{}
|
||||
<- client.req
|
||||
client.availableRequests--
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -43,6 +43,10 @@ var getLead = mtool.T("get-leads").Func(func(flags *mtool.Flags){
|
|||
"id",
|
||||
ids,
|
||||
},
|
||||
urlenc.Value[string]{
|
||||
"with",
|
||||
"contacts",
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("GetLeadsByIDs(...): %s\n", err)
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package common
|
||||
|
||||
type Values struct {
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Value struct {
|
||||
Value any `json:"value,omitempty"`
|
||||
EnumID int `json:"enum_id,omitempty"`
|
||||
Enum string `json:"enum,omitempty"`
|
||||
|
@ -10,19 +14,32 @@ type CustomFieldsValue struct {
|
|||
FieldName string `json:"field_name,omitempty"`
|
||||
FieldCode string `json:"field_code,omitempty"`
|
||||
FieldType string `json:"field_type,omitempty"`
|
||||
Values []Values `json:"values"`
|
||||
Values []Value `json:"values"`
|
||||
}
|
||||
|
||||
type CustomFieldsValues []CustomFieldsValue
|
||||
|
||||
func (vs CustomFieldsValues) GetValuesByID(
|
||||
func (vs CustomFieldsValues) GetByID(
|
||||
id int,
|
||||
) ([]Values, bool) {
|
||||
) (CustomFieldsValue, bool) {
|
||||
for _, v := range vs {
|
||||
if v.FieldID == id {
|
||||
return v.Values, true
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
return CustomFieldsValue{}, false
|
||||
}
|
||||
|
||||
func (fields CustomFieldsValues) FilterByNameRegex(
|
||||
re *regexp.Regexp,
|
||||
) CustomFieldsValues {
|
||||
ret := CustomFieldsValues{}
|
||||
for _, field := range fields {
|
||||
if re.MatchString(field.FieldName) {
|
||||
ret = append(ret, field)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import "surdeus.su/core/ss/urlenc"
|
|||
import "errors"
|
||||
import "surdeus.su/core/amo/api"
|
||||
import "fmt"
|
||||
//import "log"
|
||||
|
||||
func (client *Client) GetContact(
|
||||
contactID int,
|
||||
|
@ -61,4 +62,5 @@ func (client *Client) UpdateContact(contact *contacts.Contact) error {
|
|||
contact.ID,
|
||||
contact,
|
||||
)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue