wilr / grunt-shopify

Grunt plug-in for publishing Shopify theme assets
BSD 3-Clause "New" or "Revised" License
107 stars 32 forks source link

Download is throttled #58

Closed Austinb closed 8 years ago

Austinb commented 8 years ago

It appears the download side is throttled as well so when you try to do a theme download it ends up erroring out.

$ grunt shopify:download
...
>> [grunt-shopify] - File "assets/j..." saved to disk.
>> [grunt-shopify] - Downloading "...".
>> [grunt-shopify] - File "assets/..." saved to disk.
Warning: Request limit exceeded for the Shopify API Use --force to continue.

Aborted due to warnings.
$

So the call should be tied into the same rate_limit_delay setting as the upload side. I did a quick hack and added a sleep loop using the current time and then doing a while loop but it is ugly since I am still new to nodeJS. There should be something more elegant added to the theme download side.

I just made a function called sleep and added it after the shopify.download(path.join(basePath, asset.key), next); call in lib/shopify.js

// At the top
function sleep(callback) {
    var now = new Date().getTime();
    while(new Date().getTime() < now + 500) {
        // do nothing
    }
}

// In the shopify.downloadTheme = function(done) {
async.eachSeries(obj.assets, function(asset, next) {
shopify.download(path.join(basePath, asset.key), next);
sleep(function() {});
afreeland commented 8 years ago

Has this issue been addressed...or any other none workarounds?

wilr commented 8 years ago

Fixed in 6605dda