akaszynski / keepa

Python Keepa.com API
https://keepaapi.readthedocs.io/en/latest/
Apache License 2.0
241 stars 77 forks source link

wait for tokens is waiting 1 second each time #109

Closed threemonks closed 2 years ago

threemonks commented 3 years ago

I have version 1.3.0, it seems to be printing wait for 60 seconds, then 59 seconds, then 58 seconds, etc. Is this expected? I'd expect it to wait until the timetorefill, which is calculated by

        # Get current timestamp in milliseconds from UNIX epoch
        now = int(time.time() * 1000)
        timeatrefile = self.status['timestamp'] + self.status['refillIn']

        # wait plus one second fudge factor
        timetorefil = timeatrefile - now + 1000
        if timetorefil < 0:
            timetorefil = 0

        # Account for negative tokens left
        if self.tokens_left < 0:
            timetorefil += (abs(self.tokens_left) / self.status['refillRate']) * 60000

        # Return value in seconds
        return timetorefil / 1000.0

So if the first time it prints wait for 60 seconds, then it should not print anything, but rather wait until 60 seconds is up, and there's now enough new token to complete the action, then proceed.

Am I misunderstanding this?

akaszynski commented 3 years ago

So if the first time it prints wait for 60 seconds, then it should not print anything, but rather wait until 60 seconds is up, and there's now enough new token to complete the action, then proceed.

Correct, that's how it was intended to work: https://github.com/akaszynski/keepa/blob/ffc35edc2f7a4601408b0f0a22a8856be88dcb3e/keepa/interface.py#L412-L416

I'm not sure why it's then printing 59, ... does this occur only when using async?

threemonks commented 2 years ago

Sorry, missed this reply. I was using wait=True, so that is sync mode.

akaszynski commented 2 years ago

Closing stale issue. Reopen is this is still an issue.