Skip to content

Commit

Permalink
Fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
breathbath committed Jun 15, 2020
1 parent cefa444 commit 1decd0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
19 changes: 15 additions & 4 deletions examples/products/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"crypto/tls"
"flag"
"fmt"
"github.com/erply/api-go-wrapper/pkg/api"
Expand All @@ -18,12 +19,20 @@ func main() {
clientCode := flag.String("cc", "", "client code")
flag.Parse()

connectionTimeout := 60 * time.Second
transport := &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
ResponseHeaderTimeout: connectionTimeout,
}
httpCl := &http.Client{Transport: transport}

sessionKey, err := auth.VerifyUser(*username, *password, *clientCode, http.DefaultClient)
if err != nil {
panic(err)
}

apiClient, err := api.NewClient(sessionKey, *clientCode, nil)
apiClient, err := api.NewClient(sessionKey, *clientCode, httpCl)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -80,8 +89,8 @@ func GetProductsInParallel(cl *api.Client) ([]products.Product, error) {
sharedCommon.ListingSettings{
MaxRequestsCountPerSecond: 5,
StreamBufferLength: 10,
MaxItemsPerRequest: 10,
MaxFetchersCount: 2,
MaxItemsPerRequest: 300,
MaxFetchersCount: 10,
},
productsDataProvider,
func(sleepTime time.Duration) {
Expand All @@ -92,7 +101,9 @@ func GetProductsInParallel(cl *api.Client) ([]products.Product, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 5)
defer cancel()

prodsChan := lister.Get(ctx, map[string]interface{}{})
prodsChan := lister.Get(ctx, map[string]interface{}{
"changedSince": time.Date(2020, 2, 15, 0, 0, 0, 0, time.UTC).Unix(),
})

prods := make([]products.Product, 0)
var err error
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/common/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (p *Lister) getCursors(ctx context.Context, totalCount int) chan []Cursor {
},
)
curPage++
leftCount -= limit //leftCount 900
leftCount -= limit
}
select {
case out <- cursorsForBulkRequest:
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/products/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func NewListingDataProvider(erplyClient Manager) *ListingDataProvider {
}

func (l *ListingDataProvider) Count(ctx context.Context, filters map[string]interface{}) (int, error) {
filters["recordsOnPage"] = 1
filters["pageNo"] = 1

resp, err := l.erplyAPI.GetProductsBulk(ctx, []map[string]interface{}{filters}, map[string]string{})

if err != nil {
Expand Down

0 comments on commit 1decd0f

Please sign in to comment.