Code Monkey home page Code Monkey logo

Comments (5)

baorv avatar baorv commented on June 13, 2024

I totally agree with to you. The api limit check is still not optimized

from shopify.

baorv avatar baorv commented on June 13, 2024

Do you have any idea to deal with this problem? @Art3miX

from shopify.

Art3miX avatar Art3miX commented on June 13, 2024

I didn't use this lib in the end and can't do a pull request.

But yea, its pretty easy to change it.

in client.php :
getCallLimit should return the exact number of request left, so we take the bucket size and reduce the amount of calls we already did :
return $this->call_bucket - $this->call_limit;

callLimitReached should return true if 1 or less requests left (just in case we leave extra 1 request in bucket).
return $this->getCallLimit() <= 1;

And the sleep should be changed to 1 second, because shopify give us 2 requests each second, so we wait 1 second and we get extra 2 requests, this will ensure us we only wait the minimum time needed between requests.
in request function:

if ($this->rate_limit && self::$delay_next_call) {
      // Sleep a random amount of time to help prevent bucket overflow.
      usleep(1 * 1000000);
    }

Sorry for this poor answer, but this should get you going (unless i forgot something), i'm sure someone can find the time to do a pull request.

from shopify.

baorv avatar baorv commented on June 13, 2024

Ok. I think it's great idea. But how can I do it inside this lib without processing in the request method?

from shopify.

baorv avatar baorv commented on June 13, 2024

I found a solve in the internet by reading header named Retry-After, but I don't test it.

from shopify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.