Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Make 'retry' plugin compatible with pipes #154

Closed
l2fprod opened this issue Oct 28, 2016 · 1 comment
Closed

Make 'retry' plugin compatible with pipes #154

l2fprod opened this issue Oct 28, 2016 · 1 comment

Comments

@l2fprod
Copy link

l2fprod commented Oct 28, 2016

Currently the new retry plugin is incompatible with pipes. If one tries to upload/download an attachment with pipe and has enabled the retry plugin, it generates an error:

TypeError: Cannot read property 'pipe' of undefined

and

/Users/fred/dev/whisk/openwhisk-darkvisionapp/web/node_modules/cloudant/plugins/retry.js:58
      callback(results[0], results[1], results[2])
      ^

TypeError: callback is not a function
    at /Users/fred/dev/whisk/openwhisk-darkvisionapp/web/node_modules/cloudant/plugins/retry.js:58:7
    at /Users/fred/dev/whisk/openwhisk-darkvisionapp/web/node_modules/cloudant/node_modules/async/dist/async.js:988:16

The retry plugin should adapt or there should be a way to bypass the retry plugin when calling get/insert for attachments.

My current solution is to have two cloudant objects, one where retry is enabled, one without used only to deal with attachments. Specially in the case of an upload I don't want to load the attachment in memory to send it to cloudant but rather I want to stream it from the disk to cloudant.

@glynnbird
Copy link
Contributor

You are correct. With the default plugin, when you call a cloudant library function you are returned the request object that is responsible for making the request. This allows you to stream the reply using the Node.js streams API or pipe it to an output stream.

When using the retry plugin, we cannot asynchronously return the request that does the work because it might not be the first request.

The work-around you suggested is the same recommendation I gave in this blog.

Your attachment work-around is fine, but there are other cases when it is desirable to stream the data e.g. downloading large cuts of data.

glynnbird added a commit to glynnbird/nodejs-cloudant that referenced this issue Nov 4, 2016
glynnbird added a commit that referenced this issue Nov 4, 2016
make retry plugin return a stream. Fixes issue #154
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants