Skip to content

Commit

Permalink
fix(queue-worker/kickoff): make crawls wait for kickoff to finish (ma…
Browse files Browse the repository at this point in the history
…tters on big sitemapped sites)
  • Loading branch information
mogery committed Jan 17, 2025
1 parent 23bb172 commit d5929af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/api/src/lib/crawl-redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,18 @@ export async function isCrawlFinished(id: string) {
return (
(await redisConnection.scard("crawl:" + id + ":jobs_done")) ===
(await redisConnection.scard("crawl:" + id + ":jobs"))
&& (await redisConnection.get("crawl:" + id + ":kickoff:finish")) !== null
);
}

export async function isCrawlFinishedLocked(id: string) {
return await redisConnection.exists("crawl:" + id + ":finish");
}

export async function finishCrawlKickoff(id: string) {
await redisConnection.set("crawl:" + id + ":kickoff:finish", "yes", "EX", 24 * 60 * 60);
}

export async function finishCrawl(id: string) {
if (await isCrawlFinished(id)) {
_logger.debug("Marking crawl as finished.", {
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/services/queue-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
addCrawlJobs,
crawlToCrawler,
finishCrawl,
finishCrawlKickoff,
generateURLPermutations,
getCrawl,
getCrawlJobCount,
Expand Down Expand Up @@ -675,6 +676,9 @@ async function processKickoffJob(job: Job & { id: string }, token: string) {

logger.debug("Done queueing jobs!");

await finishCrawlKickoff(job.data.crawl_id);
await finishCrawlIfNeeded(job, sc);

return { success: true };
} catch (error) {
logger.error("An error occurred!", { error });
Expand Down

0 comments on commit d5929af

Please sign in to comment.