Usage testing actor
Pricing
Pay per usage
Go to Store

Usage testing actor
Actor for testing different platform usage types
0.0 (0)
Pricing
Pay per usage
2
Total users
3
Monthly users
3
Runs succeeded
0%
Last modified
3 years ago
.editorconfig
root = true
[*]indent_style = spaceindent_size = 4charset = utf-8trim_trailing_whitespace = trueinsert_final_newline = trueend_of_line = lf
.eslintrc
{ "extends": "@apify"}
.gitignore
# This file tells Git which files shouldn't be added to source control
.ideanode_modules
Dockerfile
# First, specify the base Docker image. You can read more about# the available images at https://sdk.apify.com/docs/guides/docker-images# You can also use any other image from Docker Hub.FROM apify/actor-node:16
# Second, copy just package.json and package-lock.json since it should be# the only file that affects "npm install" in the next step, to speed up the buildCOPY package*.json ./
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --only=prod --no-optional \ && echo "Installed NPM packages:" \ && (npm list --only=prod --no-optional --all || true) \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version
# Next, copy the remaining files and directories with the source code.# Since we do this after NPM install, quick build will be really fast# for most source file changes.COPY . ./
# Optionally, specify how to launch the source code of your actor.# By default, Apify's base Docker images define the CMD instruction# that runs the Node.js source code using the command specified# in the "scripts.start" section of the package.json file.# In short, the instruction looks something like this:## CMD npm start
INPUT_SCHEMA.json
{ "title": "Input schema for the apify_project actor.", "type": "object", "schemaVersion": 1, "properties": { "test": { "title": "Test", "type": "string", "description": "There is testing input field description.", "editor": "textfield" } }, "required": []}
apify.json
{ "env": { "npm_config_loglevel": "silent" }}
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 writes9 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 input19 // 3 key-value store writes, 3 MB internal transfer20 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 transfer26 console.log('Reading from key-value store...')27 await Apify.getValue('OUTPUT');28 await Apify.getValue('OUTPUT');29
30 // 6 dataset reads31 console.log('Reading from dataset...')32 // Wait for MongoUpdateThrottled33 await Apify.utils.sleep(5000);34 const dataset = await Apify.openDataset();35 const datasetData = await dataset.getData();36
37 // 1 key-value store list38 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 writes44 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 reads51 console.log('Reading from request queue...')52 const request = await queue.fetchNextRequest()53 await queue.getRequest(request.id);54
55 // 1 MB external transfer56 console.log('Doing external network request...')57 await axios.post('https://example.com', megabyteFile);58});
megabyte_image.jpeg
package.json
{ "name": "project-empty", "version": "0.0.1", "description": "This is a boilerplate of an Apify actor.", "dependencies": { "apify": "^2.3.2" }, "devDependencies": { "@apify/eslint-config": "^0.1.3", "eslint": "^7.0.0" }, "scripts": { "start": "node main.js", "lint": "./node_modules/.bin/eslint ./src --ext .js,.jsx", "lint:fix": "./node_modules/.bin/eslint ./src --ext .js,.jsx --fix", "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1" }, "author": "It's not you it's me", "license": "ISC"}