Introducing Handlers (new in 1.3.0-alpha) #117
Unanswered
blakebyrnes
asked this question in
Show and tell
Replies: 1 comment
-
Nice! If you plan on more future blog posts, could you consider adding a RSS and/or Atom feed to your site? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is cross-posted from our new blog at https://secretagent.dev/blog (will be pushed with 1.3.0-alpha.1)
When you start using SecretAgent, you often copy and paste the default examples. As we started to use SecretAgent on larger extraction efforts, it became clear that we didn't have a clear story for "how" you go from that starting example to running 2, or even 1000 scrapes.
As you start to think about structuring a bigger effort, a bunch of questions come up:
As we explored simplifying this story, we wanted to make the progression of "examples" through to full-scrapes a smooth process. Something like this:
Step 1: Try Out an Example
Trying out examples should require as little setup as possible, so we added a new
default export
that's a ready-to-go client for SecretAgent.Step 2: Run Multiple Scrapes
Agent instances are lightweight, but what do you do when you need to queue up thousands of them to run. Until now, you've been on your own to use libraries like
p-queue
, keeping track of promises, or simply waiting and looping.We introduced a new idea into SecretAgent called a
Handler
to help run multiple scrapes in one session. Handlers manage the concurrency of multiple scrapes to ensure your machine doesn't get overloaded and hang. We designed it so your code should require almost no changes to transition to many scrapes.Step 3: Add Scraping Machines
You might find that you need to increase the speed of your scrapes. So the next transition you'll likely want to make is to add remote machines. Handlers are built to round-robin between multiple
CoreConnections
.Default Exports
To get to this setup, you'll notice some changes in the default exports when you install SecretAgent 1.3.0-alpha.1. The default exports that come out of the
secret-agent
and@secret-agent/client
packages is now a pre-initialized instance of theAgent
class (SecretAgent
was renamed toAgent
).Handler
andAgent
are available as exports from both thesecret-agent
and@secret-agent/client
if you'd like to continue to use those. To customize a "Remote"SecretAgent
for anAgent
, you can create a new instance with acoreConnection
parameter, or use the.configure()
function.That's it!
That's our change. We hope it leads to a very simple model to understand how to scale up your SecretAgent instances. Feedback is welcome as always on any of our channels (listed in header)!
Beta Was this translation helpful? Give feedback.
All reactions