question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow consumption of requests

See original GitHub issue

Currently, in the run method of the core Stoq class, a provider can only add payloads to the payload_queue. When a payload is consumed in the _consume method, a Request is created with the request_meta that is provided to the run method. This does not allow me to specify specific request_meta for each payload added to the queue by the provider plugin. I propose that the payload_queue be renamed provider_queue and allow Requests to be added to this queue: Here are some of the changes I would make:

 async def _consume(
        self,
        provider_queue: asyncio.Queue,
        request_meta: Optional[RequestMeta] = None,
        add_start_dispatch: Optional[List[str]] = None,
    ) -> None:
        while True:
            try:
                task = await provider_queue.get()
                # Determine whether the provider has returned a `Payload`, or a task.
                # If it is a task, load the defined archiver plugin to load the
                # `Payload`, otherwise, simply continue on with the scanning.
                if isinstance(task, Payload):
                    request = Request([task], request_meta)
                    await self.scan_request(request, add_start_dispatch)
                elif isinstance(task, Request):
                    await self.scan_request(request, add_start_dispatch)
                else:

To show you the benefit of this, currently the dirmon public plugin sets the source_dir in the payload_meta, when really, I would argue such information belongs in the request_meta. If the framework supported providing Requests, dirmon could be modified as follows:

self.log.info(f'Monitoring {self.source_dir} for newly created files...')
async for changes in awatch(self.source_dir):
    for change in list(changes):
        event = change[0]
        src_path = os.path.abspath(change[1])
        # Only handle Change.added
        if event != 1:
            continue        
        payload_meta = PayloadMeta(
            extra_data={
                'filename': os.path.basename(src_path),
            }
        )
        request_meta = RequestMeta(
            extra_data={
                'source_dir': os.path.dirname(src_path),
            }
        )
        with open(src_path, 'rb') as f:
            payload = Payload(f.read(), payload_meta)
            request = Request([payload], request_meta)
            await queue.put(request)

Let me know if you think this is a worthwhile enhancement.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ytreistercommented, Dec 10, 2021

I agree that it would have to be documented, I will submit a PR when I have time to add this enhancement.

0reactions
brbickelcommented, Jan 6, 2022

Thanks for the reminder @ytreister. Looks good, merged into master.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using @Consumes and @Produces to Customize Requests ...
The @Consumes annotation is used to specify which MIME media types of representations a resource can accept, or consume, from the client. If...
Read more >
Advanced Usage — Requests 2.28.1 documentation
The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, ......
Read more >
Limits and Quotas on API Requests | Analytics Reporting API v4
If your application makes all API requests from a single IP address (i.e., on behalf of your users), use the userIP or quotaUser...
Read more >
Python's Requests Library (Guide)
You'll learn how to use requests efficiently and stop requests to external services from ... Let's dive a little deeper into the response...
Read more >
Requests limits and allocations - Power Platform
3 The Power Automate per flow plan allows capacity to be ... This doesn't use the non-licensed user request limits at the tenant...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found