Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Refactoring some code + Added deleteQueue functionality + Added test for the new QueueScheduler #113

Closed
wants to merge 16 commits into from

Conversation

pwrnrd
Copy link
Contributor

@pwrnrd pwrnrd commented Jan 9, 2019

I refactored some code, especially related to Queue.js. I think Queue.js would benefit from some more refactoring, becasue for someone not intimately known with the code, the code might be a bit confusing. QueueItem for example, needs different callbacks from the Queue. It would be nice if we delineate the different classes even more. For example, what we could do is:

  • Use QueueScheduler to store the queues, handle the execution and results of the queue.
  • Use Queue to run queue items and to handle queueitem responses.
  • Use QueueItem to run the request.

At this moment, QueueItem depends on three functions in Queue. It would be nice if we were able to reduce the amount of calls to Queue to one onComplete call.

P.S. I haven't tested this code with API keys, so there might be errors.

@ericblade
Copy link
Owner

Since the one commit says "start refactoring", should I take it that you intend to add more commits to this? Or should I review as is?

@pwrnrd
Copy link
Contributor Author

pwrnrd commented Jan 10, 2019

As is. The reason why I named it "start refactoring" is because I think that Queue.js would benefit from some more restructuring. However it would be very hard for me to do so, because I'm not familiar with a lot of choices that were made. Would you be willing to look into that?

lib/endpoints/Queue.js Outdated Show resolved Hide resolved
lib/index.js Outdated Show resolved Hide resolved
@@ -55,13 +55,14 @@ class Queue {
action,
maxInFlight,
restoreRate,
}) {
}, deleteQueueFromSchedule) {
Copy link
Owner

@ericblade ericblade Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think if we had Queue extend EventEmitter, and emit an 'empty' event that the QueueScheduler listens for in register(), rather than passing in a new parameter here?
could probably do same thing with QueueItem . . . might make more sense overall than passing around function parameters, as much as we do love passing around functions in modern JS :-D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a huge fan of decoupling code and I'm definitely not a fan of passing functions around as it clutters the arguments of the functions to which they are passed. I also agree with you that it would be nice that when we apply this pattern, that we also apply it to QueueItems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very curious, what do you think about delineating the classes even further in, for example, a QueueScheduler, Queue and QueueItem?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, let's do that EventEmitter then. And isn't that what the current patch changes the classes to, having 3?

Copy link
Contributor Author

@pwrnrd pwrnrd Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it's a start, but the classes are not yet sufficiently disentangled. I wanted to shoot this idea by you, to see what you think. One of the things that we could do for example is to put the maxInFlight and restoreRate on the QueueScheduler. However, this is hard for me to do as I'm not familiar with some of the choices.

To give an example:

if (this.inFlight >= this.maxInFlight * 0.5) {
	this.throttle();
}

Why are we multiplying the maxInFlight times 0.5?
I think that you thought very well about these choices (I don't doubt that they are necessary), but it's hard for someone not familiar with your reasoning to understand why these kind of choices were made. Therefore, I'm afraid that if I start working on disentangling everything further, I'll break the whole thing. Hence, I was wondering whether you could take a look at that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel particularly strongly about that one way or the other, wrt which one has the maxInFlight and restoreRate, but it was put there as is, because it's directly associated to the Queue. Queue keyed by sellerId/category/endpointname.

It seemed prudent to assume that we're very likely to hit a throttle point for sure if we fill the queue halfway already. As far as thought about that specific number goes, I'm pretty sure that i was still seeing a whole lot of requests get to Amazon that I didn't expect to, if I fired a few hundred rapidly, so I tweaked it down to assume that if we've reached the halfway point, we're probably going to fill the queue anyway. Of course, there might also have been a fair amount of hitting hourly quota going rather than inflight quota while i was testing it.

I make no claims that it's the best way, only that it does a pretty decent job at not over-spamming the FBA servers.

:)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was out for a couple of weeks on a work trip. Did you have it in mind to continue with some of the changes we've talked about here, or do it separately from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ericblade! I didn't get around to doing that. I propose to that in a separate PR. I did work on extending the functionality of the package locally though. However, the code I wrote for doing that is not polished, I could create a new PR for that? Then you can check if you think the code is good enough to be pulled... If not, I'd totally understand.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always glad to have a look. i've been burning hard on a R&D project that is going to a demo phase this week, so haven't had any time to work on my own apps, or this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry, I know how it is. Good luck with the project!

ericblade added a commit that referenced this pull request Aug 6, 2019
@ericblade
Copy link
Owner

@pwrnrd I have finally! got to this. I'm so sorry that took nigh on forever. I had to rebase it, and I don't have push access on your fork, so it went to PR #128

@ericblade ericblade closed this Aug 6, 2019
@pwrnrd
Copy link
Contributor Author

pwrnrd commented Aug 6, 2019

Thank you!!

@ericblade
Copy link
Owner

I promise I'll get to things in a more timely fashion from this point forward!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants