Resurrect run on Out of memory
Pricing
Pay per usage
Go to Store
Resurrect run on Out of memory
Simple helper actor to resurrect your runs when they run out of memory.
0.0 (0)
Pricing
Pay per usage
2
Total users
10
Monthly users
1
Runs succeeded
>99%
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
apify_storage
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
apify.json
{ "name": "resurrect-on-out-of-memory", "version": "0.0", "buildTag": "latest", "env": null, "template": "project_empty"}
package.json
{ "name": "resurrect-on-out-of-memory", "version": "0.0.1", "description": "This is a boilerplate of an Apify actor.", "dependencies": { "apify": "^2.2.2" }, "devDependencies": { "@apify/eslint-config": "^0.1.3", "eslint": "^7.0.0" }, "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"}
src/main.js
1const Apify = require('apify');2
3const { log } = Apify.utils;4
5Apify.main(async () => {6 // We should only be called via webhook7 const input = await Apify.getInput();8
9 const { email } = input;10
11 const client = Apify.newClient();12
13 const { resource } = input;14 const { id } = resource;15
16 // We check if the run was out of memory (137 status)17 const { exitCode, status } = await client.run(id).get();18
19 if (status !== 'FAILED') {20 log.warning(`Run ${id} finished with status ${status}, not FAILED. We have nothing to resurrect. `21 + `Did you configure the webhook correctly only for FAILED status?`);22 }23 const isOutOfMemory = exitCode === 137;24
25 if (isOutOfMemory) {26 log.info(`Run ${id} was out of memory (status 137), we will resurrect it.`);27 await client.run(id).resurrect();28 log.info(`Run resurrected.`);29 if (email) {30 log.info(`Sending email report and finishing`);31 const emailInput = {32 to: email,33 subject: `Apify - Run ${id} was out of memory, resurrected`,34 text: `Apify - Run ${id} was out of memory, resurrected`,35 };36 await client.actor('apify/send-mail').start(emailInput);37 }38 } else {39 log.info(`Run ${id} was not out of memory, it failed with exit code ${exitCode}. We will not resurrect it.`);40 }41});