Skip to content

Commit f7cb1a3

Browse files
enable memory setting, add successRate and runUrl
1 parent 1dc78de commit f7cb1a3

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

starter/INPUT_SCHEMA.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@
143143
"description": "Only works for Puppeteer type. Will wait on each page. You can provide number in ms or a selector.",
144144
"editor": "textfield"
145145
},
146+
"puppeteer.memory": {
147+
"title": "Memory",
148+
"type": "integer",
149+
"unit": "MB",
150+
"default": 4096,
151+
"minimum": 1024,
152+
"maximum": 32768,
153+
"description": "Must be power of 2 between 128 and 32768."
154+
},
146155
"playwright.chrome": {
147156
"title": "Chrome",
148157
"type": "boolean",
@@ -183,6 +192,15 @@
183192
"type": "string",
184193
"description": "Only works for playwright type. Will wait on each page. You can provide number in ms or a selector.",
185194
"editor": "textfield"
195+
},
196+
"playwright.memory": {
197+
"title": "Memory",
198+
"type": "integer",
199+
"unit": "MB",
200+
"default": 4096,
201+
"minimum": 1024,
202+
"maximum": 32768,
203+
"description": "Must be power of 2 between 128 and 32768."
186204
}
187205
},
188206
"required": ["urlsToCheck"]

starter/src/configs.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ACTOR_CHEERIO_CHECKER_NAME, ACTOR_PLAYWRIGHT_CHECKER_NAME, ACTOR_PUPPETEER_CHECKER_NAME } from './constants.js';
22
import type { PreparedActorConfig, ActorInputData, CreateActorRunConfig } from './typedefs.js';
33

4-
export function convertInputToActorConfigs(input: ActorInputData) {
4+
export function convertInputToActorConfigs(input: ActorInputData): PreparedActorConfig[] {
55
const configs: PreparedActorConfig[] = [];
66

77
for (const urlData of input.urlsToCheck) {
88
if (input['checkers.cheerio']) {
99
configs.push(...createActorRunConfigForCrawler({ input, urlData, checkerId: ACTOR_CHEERIO_CHECKER_NAME }));
1010
}
1111
if (input['checkers.puppeteer']) {
12-
configs.push(...createActorRunConfigForCrawler({ input, urlData, checkerId: ACTOR_PUPPETEER_CHECKER_NAME }));
12+
configs.push(...createActorRunConfigForCrawler({ input, urlData, checkerId: ACTOR_PUPPETEER_CHECKER_NAME, memory: input['puppeteer.memory'] }));
1313
}
1414
if (input['checkers.playwright']) {
1515
// Create a run config for each playwright browser
@@ -19,6 +19,7 @@ export function convertInputToActorConfigs(input: ActorInputData) {
1919
urlData,
2020
checkerId: ACTOR_PLAYWRIGHT_CHECKER_NAME,
2121
playwrightBrowser: 'chrome',
22+
memory: input['playwright.memory'],
2223
}));
2324
}
2425
if (input['playwright.firefox']) {
@@ -27,6 +28,7 @@ export function convertInputToActorConfigs(input: ActorInputData) {
2728
urlData,
2829
checkerId: ACTOR_PLAYWRIGHT_CHECKER_NAME,
2930
playwrightBrowser: 'firefox',
31+
memory: input['playwright.memory'],
3032
}));
3133
}
3234
if (input['playwright.webkit']) {
@@ -35,6 +37,7 @@ export function convertInputToActorConfigs(input: ActorInputData) {
3537
urlData,
3638
checkerId: ACTOR_PLAYWRIGHT_CHECKER_NAME,
3739
playwrightBrowser: 'webkit',
40+
memory: input['playwright.memory'],
3841
}));
3942
}
4043
}
@@ -43,7 +46,7 @@ export function convertInputToActorConfigs(input: ActorInputData) {
4346
return configs;
4447
}
4548

46-
function* createActorRunConfigForCrawler({ input, urlData, checkerId, playwrightBrowser }: CreateActorRunConfig) {
49+
function* createActorRunConfigForCrawler({ input, urlData, checkerId, playwrightBrowser, memory }: CreateActorRunConfig) {
4750
for (const group of input.proxyConfiguration.apifyProxyGroups ?? ['auto']) {
4851
const config: PreparedActorConfig = {
4952
actorId: checkerId,
@@ -67,7 +70,7 @@ function* createActorRunConfigForCrawler({ input, urlData, checkerId, playwright
6770
navigationTimeoutSecs: input.navigationTimeoutSecs,
6871
},
6972
params: {
70-
memory: checkerId === ACTOR_CHEERIO_CHECKER_NAME ? 4096 : 8192,
73+
memory: memory || (checkerId === ACTOR_CHEERIO_CHECKER_NAME ? 4096 : 8192),
7174
timeout: 24 * 3600,
7275
},
7376
};

starter/src/startRunAndPool.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ export async function waitForRunToFinishAndPushData(runConfig: PreparedActorConf
3030
value.playwrightBrowser = 'webkit';
3131
}
3232

33+
value.successRate = Number(((value.success / value.totalPages) * 100).toFixed(2));
34+
value.runUrl = `https://console.apify.com/actors/runs/${runConfig.runId}`;
35+
3336
await Actor.pushData(value);
3437
}

starter/src/typedefs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface ActorInputData {
5353
'puppeteer.headfull'?: boolean;
5454
'puppeteer.useChrome'?: boolean;
5555
'puppeteer.waitFor'?: string;
56+
'puppeteer.memory'?: number;
5657

5758
// Pass only to playwright
5859
'playwright.chrome'?: boolean;
@@ -61,6 +62,7 @@ export interface ActorInputData {
6162
'playwright.headfull'?: boolean;
6263
'playwright.useChrome'?: boolean;
6364
'playwright.waitFor'?: string;
65+
'playwright.memory'?: number;
6466
}
6567

6668
export interface PreparedActorConfig {
@@ -81,6 +83,7 @@ export interface CreateActorRunConfig {
8183
input: ActorInputData;
8284
urlData: UrlInput;
8385
playwrightBrowser?: 'chrome' | 'firefox' | 'webkit';
86+
memory?: number;
8487
}
8588

8689
export interface UrlCheckResult {
@@ -102,6 +105,9 @@ export interface ActorCheckDetailedOutput {
102105
url: string;
103106
simplifiedOutput: string;
104107
detailedOutput: string;
108+
runUrl: string;
109+
110+
successRate?: number;
105111

106112
// Page data
107113
totalPages: UrlCheckResult[];

0 commit comments

Comments
 (0)