from lazycloud import App, Autoscaler, Map, Queue
app = App("crawler")
frontier = Queue("crawl-frontier")
seen = Map("crawl-seen")
@app.function(
cpu=1,
memory="512Mi",
timeout_seconds=3600,
retries=0,
autoscaler=Autoscaler(max_containers=8),
)
def crawl_worker() -> int:
handled = 0
while (url := frontier.pop()) is not None:
if url in seen:
continue
seen.set(url, True, ttl=86400)
for link in fetch_links(url): # your fetch code
frontier.put(link)
handled += 1
return handled
if __name__ == "__main__":
frontier.put("https://example.com/")
calls = crawl_worker.spawn_map([() for _ in range(8)])
print(sum(call.get() for call in calls))