lawos icon indicating copy to clipboard operation
lawos copied to clipboard

then should accept a function rather than Promise.all directly

Open geoffdutton opened this issue 7 years ago • 7 comments

Potential fix for #1 (if #1 is even an issue).

Is this the intended behavior? If any one of the Item callbacks rejects, it should quit?

geoffdutton avatar Jun 27 '17 03:06 geoffdutton

I for one think you're right and I'm using the same fix. I was writing my tests today and making sure the handler could fail and leave the item in the queue wasn't happening until I applied this.

tenKinetic avatar Jun 28 '17 11:06 tenKinetic

Cool, yeah I think it's because the Promise.all gets executed right away before the first promise resolves. So I think in practice it's probably actually deleting messages before knowing if the processing of such message was successful or not.

geoffdutton avatar Jun 28 '17 13:06 geoffdutton

I've been using this in a production lambda, it's working well. Let me know what you think about my latest changes. Basically I pass all the items to the item callback, and only delete the items that resolved successfully.

Do you think it'd be helpful to have some type of error callback? That way you handle caught promise rejections further down the chain if desired.

Also, what's the use case for handling the whole list of messages vs one message at a time? I.e. item(cb) vs list(cb)?

geoffdutton avatar Jun 28 '17 14:06 geoffdutton

@geoffdutton thanks for this! I just finished doing nearly the exact same thing myself and was coming to make a PR when I saw this! One thing that I might suggest, as you are now tracking failed requests in the metrics, I added another count for success in order to present a clear picture of the results. eg { processed: x, resolved: x, rejected: x, iterations: x }. Just something I found useful

Iodine- avatar Jul 07 '17 20:07 Iodine-

If this works can we get it on master, so people that are using NPM don't need to hunt this down :)

achadee avatar Mar 15 '18 02:03 achadee

Agreed with @achadee.

joshband avatar Mar 19 '18 20:03 joshband

Just checking in on the status of the code merge for this PR. Very useful so looking forward to seeing this merged. Thanks!

joshband avatar Jul 24 '18 17:07 joshband