Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Removed old unused Apify.readyFreddy() function

Jan Curn5c18e1b430fd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6753f8e58..df213ba35 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
xxx
===================
- Replaced git-hosted version of our fork of ps-tree with @apify/ps-tree package
+- Removed old unused Apify.readyFreddy() function
0.6.0 / 2018-08-17
===================
diff --git a/src/actor.js b/src/actor.js
index cf1932766..0eba396d2 100644
--- a/src/actor.js
+++ b/src/actor.js
@@ -194,25 +194,6 @@ export const main = (userFunc) => {
}
};
-// TODO: this should rather be called Apify.listeningOnPort() or something like that
-
-/**
- * Notifies Apify runtime that actor is listening on port specified by the APIFY_INTERNAL_PORT environment
- * variable and is ready to receive a HTTP request with actor input.
- *
- * @ignore
- */
-export const readyFreddy = () => {
- const watchFileName = process.env[ENV_VARS.WATCH_FILE];
- if (watchFileName) {
- fs.writeFile(watchFileName, '', (err) => {
- if (err) console.log(`WARNING: Cannot write to watch file ${watchFileName}: ${err}`);
- });
- } else {
- console.log(`WARNING: ${ENV_VARS.WATCH_FILE} environment variable not specified, readyFreddy() has no effect.`);
- }
-};
-
/**
* Runs an actor on the Apify platform using the current user account (given by the `APIFY_TOKEN` environment variable),
diff --git a/src/index.js b/src/index.js
index f0620a7cc..b573ba082 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,6 +1,6 @@
import log from 'apify-shared/log';
import { ENV_VARS } from './constants';
-import { main, readyFreddy, getEnv, call, getApifyProxyUrl } from './actor';
+import { main, getEnv, call, getApifyProxyUrl } from './actor';
import AutoscaledPool from './autoscaled_pool';
import BasicCrawler from './basic_crawler';
import { pushData, openDataset } from './dataset';
@@ -43,7 +43,6 @@ module.exports = {
main,
getEnv,
call,
- readyFreddy,
getMemoryInfo,
getApifyProxyUrl,
isAtHome,
diff --git a/test/actor.js b/test/actor.js
index ee57ee70f..07af5ef4e 100644
--- a/test/actor.js
+++ b/test/actor.js
@@ -34,103 +34,6 @@ before(() => {
const popFreePort = () => freePorts.pop();
*/
-const createWatchFile = () => {
- const tmpobj = tmp.fileSync();
- const path = tmpobj.name;
- fs.writeSync(tmpobj.fd, 'bla bla bla bla');
-
- const stat = fs.statSync(path);
- expect(stat.size).to.be.greaterThan(0);
- return path;
-};
-
-const testWatchFileWillBecomeEmpty = (path, waitMillis) => {
- const startedAt = Date.now();
- return new Promise((resolve, reject) => {
- const intervalId = setInterval(() => {
- const stat = fs.statSync(path);
- if (stat.size !== 0) {
- if (Date.now() - startedAt >= waitMillis) {
- reject(`Watch file not written in ${waitMillis} millis`); // eslint-disable-line prefer-promise-reject-errors
- }
- } else {
- clearInterval(intervalId);
- resolve();
- }
- }, 20);
- });
-};
-
-/*
-const testMain = (method, bodyRaw, contentType, userFunc, expectedExitCode = 0) => {
- const port = popFreePort();
- process.env.APIFY_INTERNAL_PORT = port;
- process.env.APIFY_WATCH_FILE = createWatchFile();
-
- // intercept calls to process.exit()
- const EMPTY_EXIT_CODE = 'dummy';
- let exitCode = EMPTY_EXIT_CODE;
- process.exit = (code) => {
- exitCode = code;
- };
-
- return new Promise((resolve, reject) => {
- let expectedBody = bodyRaw;
- if (contentType === 'application/json') expectedBody = JSON.parse(bodyRaw);
-
- // give server a little time to start listening before sending the request
- setTimeout(() => {
- const req = {
- url: `http://127.0.0.1:${port}/`,
- method,
- body: bodyRaw,
- headers: {},
- timeout: 1000,
- };
- if (contentType) req.headers['Content-Type'] = contentType;
-
- request(req, (err) => {
- if (err) return reject(err);
- });
- }, 20);
-
- Apify.main((opts) => {
- // console.dir(opts);
- try {
- expect(opts.input.method).to.equal(method);
- if (contentType) expect(opts.input.contentType).to.equal(contentType);
- expect(opts.input.body).to.deep.equal(expectedBody);
- resolve();
- } catch (err) {
- reject(err);
- }
- // call user func to test other behavior
- if (userFunc) userFunc(opts);
- });
- })
- .then(() => {
- // watch file should be empty by now
- return testWatchFileWillBecomeEmpty(process.env.APIFY_WATCH_FILE, 0);
- })
- .then(() => {
- // test process exit code is as expected
- return new Promise((resolve, reject) => {
- const intervalId = setInterval(() => {
- if (exitCode === EMPTY_EXIT_CODE) return;
- clearInterval(intervalId);
- // restore process.exit()
- process.exit = origProcessExit;
- try {
- expect(exitCode).to.equal(expectedExitCode);
- resolve();
- } catch (err) {
- reject(err);
- }
- }, 20);
- });
- });
-};
-*/
/**
* Helper function that enables testing of Apify.main()
@@ -318,14 +221,6 @@ describe('Apify.main()', () => {
});
});
-describe('Apify.readyFreddy()', () => {
- it('it works as expected', () => {
- process.env.APIFY_WATCH_FILE = createWatchFile();
- Apify.readyFreddy();
- return testWatchFileWillBecomeEmpty(process.env.APIFY_WATCH_FILE, 1000);
- });
-});
-
describe('Apify.call()', () => {
it('works as expected', () => {
const actId = 'some-act-id';