Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page state type fixes: #488

Merged
merged 1 commit into from Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/crawler.ts
Expand Up @@ -33,7 +33,7 @@ import { Screenshots } from "./util/screenshots.js";
import { parseArgs } from "./util/argParser.js";
import { initRedis } from "./util/redis.js";
import { logger, formatErr } from "./util/logger.js";
import { WorkerOpts, WorkerState, runWorkers } from "./util/worker.js";
import { WorkerState, runWorkers } from "./util/worker.js";
import { sleep, timedRun, secondsElapsed } from "./util/timing.js";
import { collectAllFileSources } from "./util/file_reader.js";

Expand Down Expand Up @@ -869,7 +869,7 @@ self.__bx_behaviors.selectMainBehavior();
await this.checkLimits();
}

async teardownPage({ workerid }: WorkerOpts) {
async teardownPage({ workerid }: WorkerState) {
if (this.screencaster) {
await this.screencaster.stopById(workerid);
}
Expand Down
4 changes: 3 additions & 1 deletion src/util/state.ts
@@ -1,4 +1,5 @@
import { Redis, Result, Callback } from "ioredis";
import { v4 as uuidv4 } from "uuid";

import { logger } from "./logger.js";

Expand Down Expand Up @@ -50,7 +51,7 @@ export class PageState {

workerid!: WorkerId;

pageid?: string;
pageid: string;
title?: string;
mime?: string;
ts?: Date;
Expand All @@ -72,6 +73,7 @@ export class PageState {
this.seedId = redisData.seedId;
this.depth = redisData.depth;
this.extraHops = redisData.extraHops || 0;
this.pageid = uuidv4();
this.status = 0;
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/util/worker.ts
@@ -1,7 +1,5 @@
import os from "os";

import { v4 as uuidv4 } from "uuid";

import { logger, formatErr } from "./logger.js";
import { sleep, timedRun } from "./timing.js";
import { Recorder } from "./recorder.js";
Expand Down Expand Up @@ -54,9 +52,7 @@ export async function runWorkers(
}

// ===========================================================================
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type WorkerOpts = Record<string, any> & {
type WorkerOpts = {
page: Page;
cdp: CDPSession;
workerid: WorkerId;
Expand Down Expand Up @@ -306,16 +302,12 @@ export class PageWorker {
async timedCrawlPage(opts: WorkerState) {
const workerid = this.id;
const { data } = opts;
const { url } = data;
const { url, pageid } = data;

logger.info("Starting page", { workerid, page: url }, "worker");

this.logDetails = { page: url, workerid };

// set new page id
const pageid = uuidv4();
data.pageid = pageid;

if (this.recorder) {
this.recorder.startPage({ pageid, url });
}
Expand Down