Standby PPE Actor avatar
Standby PPE Actor

Under maintenance

Pricing

Pay per event

Go to Store
Standby PPE Actor

Standby PPE Actor

Under maintenance

Developed by

Honza

Honza

Maintained by Community

5.0 (1)

Pricing

Pay per event

1

Total users

3

Monthly users

3

Last modified

a month ago

.actor/Dockerfile

# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:20
# Check preinstalled packages
RUN npm ls crawlee apify puppeteer playwright
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY 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 debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm
# 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 . ./
# Create and run as a non-root user.
RUN adduser -h /home/apify -D apify && \
chown -R apify:apify ./
USER apify
# Run the image.
CMD npm start --silent

.actor/actor.json

{
"actorSpecification": 1,
"name": "my-actor-1",
"title": "Standby Actor in JavaScript",
"description": "Standby Actor in JavaScript.",
"version": "0.0",
"buildTag": "latest",
"usesStandbyMode": true,
"meta": {
"templateId": "js-standby"
},
"dockerfile": "./Dockerfile"
}

src/main.js

1import http from 'http';
2import { Actor } from 'apify';
3import log from '@apify/log';
4
5await Actor.init();
6
7const chargeUser = async ({eventName, count}) => {
8 const chargeOptions = {
9 eventName,
10 count,
11 }
12 const chargeResult = await Actor.charge(chargeOptions)
13 log.info(`Charged user.`, { chargeOptions, chargeResult })
14}
15
16const server = http.createServer((req, res) => {
17 // Handle Apify standby readiness probe
18 // https://docs.apify.com/platform/actors/development/programming-interface/standby#readiness-probe
19 if (req.headers['x-apify-container-server-readiness-probe']) {
20 res.writeHead(200);
21 res.end('ok');
22 return;
23 }
24
25 chargeUser({eventName: 'cheap', count: 12});
26 chargeUser({eventName: 'expensive', count: 2});
27
28 res.writeHead(200, { 'Content-Type': 'text/plain' });
29 res.end(`Hello from Actor Standby!\nThanks for your money lol\n`);
30});
31
32// Listen on the standby port
33server.listen(Actor.config.get('standbyPort'));

.dockerignore

# configurations
.idea
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
node_modules
# git folder
.git

.editorconfig

root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

.eslintrc

{
"extends": "@apify",
"root": true
}

.gitignore

# This file tells Git which files shouldn't be added to source control
.DS_Store
.idea
.zed
node_modules
storage

package.json

{
"name": "js-standby-project",
"version": "0.0.1",
"type": "module",
"description": "This is an example of an Apify Actor that uses Standby mode.",
"engines": {
"node": ">=20.0.0"
},
"dependencies": {
"apify": "^3.2.6"
},
"scripts": {
"start": "node ./src/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"
}