1const Apify = require('apify');
2
3const { log } = Apify.utils;
4
5Apify.main(async () => {
6
7 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
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});