How to use the apify-shared/consts.ENV_VARS.IS_AT_HOME function in apify-shared

To help you get started, we’ve selected a few apify-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apifytech / apify-js / test / utils.js View on Github external
it('works', () => {
        expect(utils.isAtHome()).to.be.eql(false);
        process.env[ENV_VARS.IS_AT_HOME] = 1;
        expect(utils.isAtHome()).to.be.eql(true);
        delete process.env[ENV_VARS.IS_AT_HOME];
        expect(utils.isAtHome()).to.be.eql(false);
    });
});
github apifytech / apify-js / test / utils.js View on Github external
it('works', () => {
        expect(utils.isAtHome()).to.be.eql(false);
        process.env[ENV_VARS.IS_AT_HOME] = 1;
        expect(utils.isAtHome()).to.be.eql(true);
        delete process.env[ENV_VARS.IS_AT_HOME];
        expect(utils.isAtHome()).to.be.eql(false);
    });
});
github apifytech / apify-js / test / autoscaling / snapshotter.js View on Github external
await snapshotter.start();
            await emitAndWait(10);
            await emitAndWait(10);
            await emitAndWait(10);
            await emitAndWait(0);
            await snapshotter.stop();
            const cpuSnapshots = snapshotter.getCpuSample();

            expect(cpuSnapshots).to.have.lengthOf(4);
            cpuSnapshots.forEach((ss, i) => {
                expect(ss.createdAt).to.be.a('date');
                expect(ss.isOverloaded).to.be.a('boolean');
                expect(ss.isOverloaded).to.be.eql(i % 2 === 0);
            });
        } finally {
            delete process.env[ENV_VARS.IS_AT_HOME];
        }
    });
github apifytech / apify-js / test / autoscaling / snapshotter.js View on Github external
it('correctly marks CPU overloaded using Platform event', async () => {
        process.env[ENV_VARS.IS_AT_HOME] = '1';
        let count = 0;
        const emitAndWait = async (delay) => {
            events.emit(ACTOR_EVENT_NAMES.SYSTEM_INFO, {
                isCpuOverloaded: count % 2 === 0,
                createdAt: (new Date()).toISOString(),
                cpuCurrentUsage: 66.6,
            });
            count++;
            await Apify.utils.sleep(delay);
        };

        try {
            const snapshotter = new Snapshotter();
            await snapshotter.start();
            await emitAndWait(10);
            await emitAndWait(10);
github apifytech / apify-js / test / puppeteer_pool.js View on Github external
after(() => {
            delete process.env[ENV_VARS.IS_AT_HOME];
        });
        it('should work', async () => {
github apifytech / apify-js / test / actor.js View on Github external
it('works', async () => {
        const runId = 'my-run-id';
        const expectedEventTypes = ['ACTOR.RUN.SUCCEEDED'];
        const expectedRequestUrl = 'http://example.com/api';
        const expectedPayloadTemplate = '{"hello":{{world}}';
        const expectedIdempotencyKey = 'some-key';

        process.env[ENV_VARS.ACTOR_RUN_ID] = runId;
        process.env[ENV_VARS.IS_AT_HOME] = '1';

        const webhooksMock = sinon.mock(Apify.client.webhooks);

        const webhook = {
            isAdHoc: true,
            eventTypes: expectedEventTypes,
            condition: {
                actorRunId: runId,
            },
            requestUrl: expectedRequestUrl,
            payloadTemplate: expectedPayloadTemplate,
            idempotencyKey: expectedIdempotencyKey,
        };

        webhooksMock.expects('createWebhook')
            .withExactArgs({ webhook })
github apifytech / apify-js / test / autoscaled_pool.js View on Github external
before(() => {
        logLevel = log.getLevel();
        log.setLevel(log.LEVELS.ERROR);
        process.env[ENV_VARS.IS_AT_HOME] = 1;
    });
github apifytech / apify-js / test / actor.js View on Github external
webhooksMock.expects('createWebhook')
            .withExactArgs({ webhook })
            .once()
            .returns(Promise.resolve());


        await Apify.addWebhook({
            eventTypes: expectedEventTypes,
            requestUrl: expectedRequestUrl,
            payloadTemplate: expectedPayloadTemplate,
            idempotencyKey: expectedIdempotencyKey,
        });

        delete process.env[ENV_VARS.ACTOR_RUN_ID];
        delete process.env[ENV_VARS.IS_AT_HOME];

        webhooksMock.verify();
    });
github apifytech / apify-js / test / autoscaled_pool.js View on Github external
after(() => {
        log.setLevel(logLevel);
        delete process.env[ENV_VARS.IS_AT_HOME];
    });
github apifytech / apify-js / src / utils.js View on Github external
export const isAtHome = () => !!process.env[ENV_VARS.IS_AT_HOME];