Usage testing actor avatar
Usage testing actor

Pricing

Pay per usage

Go to Store
Usage testing actor

Usage testing actor

Developed by

František Nesveda

Maintained by Community

Actor for testing different platform usage types

0.0 (0)

Pricing

Pay per usage

2

Monthly users

2

0

Last modified

3 years ago

.editorconfig

1root = true
2
3[*]
4indent_style = space
5indent_size = 4
6charset = utf-8
7trim_trailing_whitespace = true
8insert_final_newline = true
9end_of_line = lf

.eslintrc

1{
2    "extends": "@apify"
3}

.gitignore

1# This file tells Git which files shouldn't be added to source control
2
3.idea
4node_modules

Dockerfile

1# First, specify the base Docker image. You can read more about
2# the available images at https://sdk.apify.com/docs/guides/docker-images
3# You can also use any other image from Docker Hub.
4FROM apify/actor-node:16
5
6# Second, copy just package.json and package-lock.json since it should be
7# the only file that affects "npm install" in the next step, to speed up the build
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --only=prod --no-optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --only=prod --no-optional --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version
21
22# Next, copy the remaining files and directories with the source code.
23# Since we do this after NPM install, quick build will be really fast
24# for most source file changes.
25COPY . ./
26
27# Optionally, specify how to launch the source code of your actor.
28# By default, Apify's base Docker images define the CMD instruction
29# that runs the Node.js source code using the command specified
30# in the "scripts.start" section of the package.json file.
31# In short, the instruction looks something like this:
32#
33# CMD npm start

INPUT_SCHEMA.json

1{
2    "title": "Input schema for the apify_project actor.",
3    "type": "object",
4    "schemaVersion": 1,
5    "properties": {
6        "test": {
7            "title": "Test",
8            "type": "string",
9            "description": "There is testing input field description.",
10            "editor": "textfield"
11        }
12    },
13    "required": []
14}

apify.json

1{
2    "env": { "npm_config_loglevel": "silent" }
3}

main.js

1const Apify = require('apify');
2const axios = require('axios');
3
4const fs = require('fs');
5const megabyteFile = fs.readFileSync('./megabyte_image.jpeg');
6
7Apify.main(async () => {
8    // 6 dataset writes
9    console.log('Writing to dataset...')
10    await Apify.pushData([{ a: 1 }]);
11    await Apify.pushData([{ a: 1 }, { a: 1 }]);
12    await Apify.pushData([{ a: 1 }, { a: 1 }, { a: 1 }]);
13
14    // console.log('Generating data...')
15    // const megabyteBuffer = Buffer.from(Array.from({ length: 1024 * 1024 }, () => Math.floor(Math.random() * 256)));
16    // console.log(`Generated data of length ${megabyteBuffer.length} bytes`);
17
18    // 1 key-value store write is platform storing run input
19    // 3 key-value store writes, 3 MB internal transfer
20    console.log('Writing to key-value store...')
21    await Apify.setValue('OUTPUT', megabyteFile, { contentType: 'image/jpeg' });
22    await Apify.setValue('OUTPUT', megabyteFile, { contentType: 'image/jpeg' });
23    await Apify.setValue('OUTPUT', megabyteFile, { contentType: 'image/jpeg' });
24    
25    // 2 key-value store writes, 2 MB internal transfer
26    console.log('Reading from key-value store...')
27    await Apify.getValue('OUTPUT');
28    await Apify.getValue('OUTPUT');
29
30    // 6 dataset reads
31    console.log('Reading from dataset...')
32    // Wait for MongoUpdateThrottled
33    await Apify.utils.sleep(5000);
34    const dataset = await Apify.openDataset();
35    const datasetData = await dataset.getData();
36
37    // 1 key-value store list
38    const keyValueStore = await Apify.openKeyValueStore();
39    await keyValueStore.forEachKey(async (key, index, info) => {
40        console.log(`Key at ${index}: ${key} has size ${info.size}`);
41    });
42    
43    // 3 request queue writes
44    console.log('Writing to request queue...')
45    const queue = await Apify.openRequestQueue();
46    await queue.addRequest({ url: 'http://example.com/aaa' });
47    await queue.addRequest({ url: 'http://example.com/bbb' });
48    await queue.addRequest({ url: 'http://example.com/foo/bar' }, { forefront: true });
49
50    // 2 request queue reads
51    console.log('Reading from request queue...')
52    const request = await queue.fetchNextRequest()
53    await queue.getRequest(request.id);
54
55    // 1 MB external transfer
56    console.log('Doing external network request...')
57    await axios.post('https://example.com', megabyteFile);
58});

megabyte_image.jpeg

package.json

1{
2    "name": "project-empty",
3    "version": "0.0.1",
4    "description": "This is a boilerplate of an Apify actor.",
5    "dependencies": {
6        "apify": "^2.3.2"
7    },
8    "devDependencies": {
9        "@apify/eslint-config": "^0.1.3",
10        "eslint": "^7.0.0"
11    },
12    "scripts": {
13        "start": "node main.js",
14        "lint": "./node_modules/.bin/eslint ./src --ext .js,.jsx",
15        "lint:fix": "./node_modules/.bin/eslint ./src --ext .js,.jsx --fix",
16        "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
17    },
18    "author": "It's not you it's me",
19    "license": "ISC"
20}

Pricing

Pricing model

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage.