Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read one entry from redis queue #136

Open
t75bernd opened this issue Dec 4, 2018 · 1 comment
Open

Read one entry from redis queue #136

t75bernd opened this issue Dec 4, 2018 · 1 comment
Labels

Comments

@t75bernd
Copy link

t75bernd commented Dec 4, 2018

Hello,

first of all: great project, and easy to use.

I have a suggestion to make for solving a problem i have, let me explain it:

  1. Add 2 urls to a queue for one spider
  2. Spider reads 2 requests and yields both of them as a request
  3. Now sometimes the following is happening in my case: Both requests are yield and i get a session key in both requests. The first one finished returns a bunch of new requests (yield a new request is not possible) and the second yielded request is waiting until the first yielded request has crawled an item (could last some minutes). In the meantime the session key of my second request is expired and it get's rejected when trying to make a new request.

My idea would be to have an attribute in the spider which allows me to define that only 1 item from the queue is read and yielded as a response.

class MySpider(RedisSpider):
    yield_1_request = True

And next_requests in spiders.py has to be changed to something like:

if req:
    yield req
    found += 1
    if hasattr(self, 'yield_1_request') and self.yield_1_request and not use_set:
        break
else:
    self.logger.debug("Request not made from data: %r", data)

In this way you still could decide for every spider if this is necessary and also it is not a big impact in the code. What do you think about the idea/implementation? Is there anything i could make better? I would also prepare a pr when this is accepted as a feature.

Thanks for your help in advance :)

@LuckyPigeon
Copy link
Collaborator

Thanks for your feedback, it's a pratical idea. I'll look into it and put it into our comming primary progress.

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

No branches or pull requests

2 participants