MCPcopy
hub / github.com/apify/crawlee / runActor

Function runActor

test/e2e/tools.mjs:158–267  ·  view source on GitHub ↗
(dirName, memory = 4096)

Source from the content-addressed store, hash-verified

156 * @param {number} [memory=4096]
157 */
158export async function runActor(dirName, memory = 4096) {
159 let stats;
160 let datasetItems;
161 let getKeyValueStoreItems;
162 let defaultKeyValueStoreItems;
163
164 const inputPath = join(dirName, '..', 'INPUT');
165 const input = fs.existsSync(inputPath) ? fs.readFileSync(inputPath) : undefined;
166 const contentType = input ? 'application/json' : undefined;
167
168 if (process.env.STORAGE_IMPLEMENTATION === 'PLATFORM') {
169 const client = Actor.newClient();
170 const id = await pushActor(client, dirName);
171 const runId = await startActorOnPlatform(client, id, input, contentType, memory);
172
173 const {
174 defaultKeyValueStoreId,
175 defaultDatasetId,
176 startedAt: runStartedAt,
177 finishedAt: runFinishedAt,
178 // id: runId,
179 buildId,
180 userId,
181 } = await client.run(runId).waitForFinish();
182
183 getKeyValueStoreItems = async (name) => {
184 const kvResult = await client.keyValueStore(name ? `${userId}/${name}` : defaultKeyValueStoreId).get();
185
186 if (kvResult) {
187 const { items: keyValueItems } = await client.keyValueStore(kvResult.id).listKeys();
188
189 if (keyValueItems.length) {
190 console.log(`[kv] View storage: https://console.apify.com/storage/key-value/${kvResult.id}`);
191 }
192
193 const entries = await Promise.all(
194 keyValueItems.map(async ({ key }) => {
195 const record = await client.keyValueStore(kvResult.id).getRecord(key, { buffer: true });
196
197 return {
198 name: record.key,
199 raw: record.value,
200 };
201 }),
202 );
203
204 return entries.filter(({ name }) => !isPrivateEntry(name));
205 }
206
207 return undefined;
208 };
209
210 const { startedAt: buildStartedAt, finishedAt: buildFinishedAt } = await client.build(buildId).get();
211
212 const buildTook = (buildFinishedAt.getTime() - buildStartedAt.getTime()) / 1000;
213 console.log(`[build] View build log: https://api.apify.com/v2/logs/${buildId} [build took ${buildTook}s]`);
214
215 const runTook = (runFinishedAt.getTime() - runStartedAt.getTime()) / 1000;

Callers 15

test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90
test.mjsFile · 0.90

Calls 15

pushActorFunction · 0.85
startActorOnPlatformFunction · 0.85
isPrivateEntryFunction · 0.85
execSyncFunction · 0.85
getStatsFunction · 0.85
getDatasetItemsFunction · 0.85
logMethod · 0.80
mapMethod · 0.80
toStringMethod · 0.80
setValueMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…