{"id":24876246,"url":"https://github.com/dotandimet/mojo-useragent-role-queued","last_synced_at":"2025-07-05T01:40:57.639Z","repository":{"id":56832702,"uuid":"115445396","full_name":"dotandimet/Mojo-UserAgent-Role-Queued","owner":"dotandimet","description":"A role for Mojo::UserAgent that processes non-blocking requests in a rate-limiting queue.","archived":false,"fork":false,"pushed_at":"2019-08-08T15:24:58.000Z","size":67,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-18T04:02:20.617Z","etag":null,"topics":["mojo","mojolicious","perl","perl5","user-agent","web-crawler"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotandimet.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-26T18:23:02.000Z","updated_at":"2024-04-18T04:02:20.618Z","dependencies_parsed_at":"2022-09-08T05:11:34.253Z","dependency_job_id":null,"html_url":"https://github.com/dotandimet/Mojo-UserAgent-Role-Queued","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotandimet%2FMojo-UserAgent-Role-Queued","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotandimet%2FMojo-UserAgent-Role-Queued/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotandimet%2FMojo-UserAgent-Role-Queued/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotandimet%2FMojo-UserAgent-Role-Queued/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotandimet","download_url":"https://codeload.github.com/dotandimet/Mojo-UserAgent-Role-Queued/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236639527,"owners_count":19181643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mojo","mojolicious","perl","perl5","user-agent","web-crawler"],"created_at":"2025-02-01T08:29:02.068Z","updated_at":"2025-02-01T08:29:03.036Z","avatar_url":"https://github.com/dotandimet.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/dotandimet/Mojo-UserAgent-Role-Queued.svg?branch=master)](https://travis-ci.org/dotandimet/Mojo-UserAgent-Role-Queued) [![MetaCPAN Release](https://badge.fury.io/pl/Mojo-UserAgent-Role-Queued.svg)](https://metacpan.org/release/Mojo-UserAgent-Role-Queued)\n# NAME\n\nMojo::UserAgent::Role::Queued - A role to process non-blocking requests in a rate-limiting queue.\n\n# SYNOPSIS\n\n       use Mojo::UserAgent;\n\n       my $ua = Mojo::UserAgent-\u003enew-\u003ewith_roles('+Queued');\n       $ua-\u003emax_redirects(3);\n       $ua-\u003emax_active(5); # process up to 5 requests at a time\n       for my $url (@big_list_of_urls) {\n       $ua-\u003eget($url, sub {\n               my ($ua, $tx) = @_;\n               if (! $tx-\u003eerror) {\n                   say \"Page at $url is titled: \",\n                     $tx-\u003eres-\u003edom-\u003eat('title')-\u003etext;\n               }\n              });\n      };\n      Mojo::IOLoop-\u003estart unless Mojo::IOLoop-\u003eis_running;\n\n      # works with promises, too:\n     my @p = map {\n       $ua-\u003eget_p($_)-\u003ethen(sub { pop-\u003eres-\u003edom-\u003eat('title')-\u003etext })\n         -\u003ecatch(sub { say \"Error: \", @_ })\n     } @big_list_of_urls;\n      Mojo::Promise-\u003eall(@p)-\u003ewait;\n    \n\n# DESCRIPTION\n\nMojo::UserAgent::Role::Queued manages all non-blocking requests made through [Mojo::UserAgent](https://metacpan.org/pod/Mojo::UserAgent) in a queue to limit the number of simultaneous requests.\n\n[Mojo::UserAgent](https://metacpan.org/pod/Mojo::UserAgent) can make multiple concurrent non-blocking HTTP requests using Mojo's event loop, but because there is only a single process handling all of them, you must take care to limit the number of simultaneous requests you make.\n\nSome discussion of this issue is available here\n[http://blogs.perl.org/users/stas/2013/01/web-scraping-with-modern-perl-part-1.html](http://blogs.perl.org/users/stas/2013/01/web-scraping-with-modern-perl-part-1.html)\nand in Joel Berger's answer here:\n[http://stackoverflow.com/questions/15152633/perl-mojo-and-json-for-simultaneous-requests](http://stackoverflow.com/questions/15152633/perl-mojo-and-json-for-simultaneous-requests).\n\n[Mojo::UserAgent::Role::Queued](https://metacpan.org/pod/Mojo::UserAgent::Role::Queued) tries to generalize the practice of managing a large number of requests using a queue, by embedding the queue inside [Mojo::UserAgent](https://metacpan.org/pod/Mojo::UserAgent) itself.\n\n# ATTRIBUTES\n\n[Mojo::UserAgent::Role::Queued](https://metacpan.org/pod/Mojo::UserAgent::Role::Queued) has the following attributes:\n\n## max\\_active\n\n    $ua-\u003emax_active(5);  # execute no more than 5 transactions at a time.\n    print \"Execute no more than \", $ua-\u003emax_active, \" concurrent transactions\"\n\nParameter controlling the maximum number of transactions that can be active at the same time.\n\n# EVENTS\n\n[Mojo::UserAgent::Role::Queued](https://metacpan.org/pod/Mojo::UserAgent::Role::Queued) adds the following event to those emitted by [Mojo::UserAgent](https://metacpan.org/pod/Mojo::UserAgent):\n\n## queue\\_empty\n\n    $ua-\u003eon(queue_empty =\u003e sub { my ($ua) = @_; .... })\n\nEmitted when the queue has been emptied of all pending jobs. In previous releases, this event was called `stop_queue` (**this is a breaking change**).\n\n## \n\n# LICENSE AND COPYRIGHT\n\nThis software is Copyright (c) 2017-2019 by Dotan Dimet \u003cdotan@corky.net\u003e.\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the Artistic License version 2.0.\n\n# AUTHOR\n\nDotan Dimet \u003cdotan@corky.net\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotandimet%2Fmojo-useragent-role-queued","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotandimet%2Fmojo-useragent-role-queued","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotandimet%2Fmojo-useragent-role-queued/lists"}