From af5644d17a99f7cf6b46638c88d5515ba986730f Mon Sep 17 00:00:00 2001 From: Torben Sorensen Date: Sat, 27 Dec 2025 22:54:51 -0800 Subject: [PATCH] add backoffs etc --- ecosystem.config.cjs | 46 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs index 01a8b1d8..7d4fd6fa 100644 --- a/ecosystem.config.cjs +++ b/ecosystem.config.cjs @@ -7,19 +7,21 @@ module.exports = { apps: [ { // --- API Server --- - // The name is now dynamically set based on the environment. - // This is a common pattern but requires you to call pm2 with the correct name. - // The deploy script handles this by using 'flyer-crawler-api' for prod and 'flyer-crawler-api-test' for test. name: 'flyer-crawler-api', script: './node_modules/.bin/tsx', - args: 'server.ts', // tsx will execute this file - max_memory_restart: '500M', // Restart if memory usage exceeds 500MB + args: 'server.ts', + max_memory_restart: '500M', + + // Restart Logic + max_restarts: 40, + exp_backoff_restart_delay: 100, + min_uptime: '10s', + // Production Environment Settings env_production: { - NODE_ENV: 'production', // Set the Node.js environment to production + NODE_ENV: 'production', name: 'flyer-crawler-api', cwd: '/var/www/flyer-crawler.projectium.com', - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -39,10 +41,9 @@ module.exports = { }, // Test Environment Settings env_test: { - NODE_ENV: 'test', // Set to 'test' to match the environment purpose and disable pino-pretty + NODE_ENV: 'test', name: 'flyer-crawler-api-test', cwd: '/var/www/flyer-crawler-test.projectium.com', - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -66,7 +67,6 @@ module.exports = { name: 'flyer-crawler-api-dev', watch: true, ignore_watch: ['node_modules', 'logs', '*.log', 'flyer-images', '.git'], - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -89,14 +89,19 @@ module.exports = { // --- General Worker --- name: 'flyer-crawler-worker', script: './node_modules/.bin/tsx', - args: 'src/services/worker.ts', // tsx will execute this file - max_memory_restart: '1G', // Restart if memory usage exceeds 1GB + args: 'src/services/worker.ts', + max_memory_restart: '1G', + + // Restart Logic + max_restarts: 40, + exp_backoff_restart_delay: 100, + min_uptime: '10s', + // Production Environment Settings env_production: { NODE_ENV: 'production', name: 'flyer-crawler-worker', cwd: '/var/www/flyer-crawler.projectium.com', - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -119,7 +124,6 @@ module.exports = { NODE_ENV: 'test', name: 'flyer-crawler-worker-test', cwd: '/var/www/flyer-crawler-test.projectium.com', - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -143,7 +147,6 @@ module.exports = { name: 'flyer-crawler-worker-dev', watch: true, ignore_watch: ['node_modules', 'logs', '*.log', 'flyer-images', '.git'], - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -166,14 +169,19 @@ module.exports = { // --- Analytics Worker --- name: 'flyer-crawler-analytics-worker', script: './node_modules/.bin/tsx', - args: 'src/services/worker.ts', // tsx will execute this file - max_memory_restart: '1G', // Restart if memory usage exceeds 1GB + args: 'src/services/worker.ts', + max_memory_restart: '1G', + + // Restart Logic + max_restarts: 40, + exp_backoff_restart_delay: 100, + min_uptime: '10s', + // Production Environment Settings env_production: { NODE_ENV: 'production', name: 'flyer-crawler-analytics-worker', cwd: '/var/www/flyer-crawler.projectium.com', - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -196,7 +204,6 @@ module.exports = { NODE_ENV: 'test', name: 'flyer-crawler-analytics-worker-test', cwd: '/var/www/flyer-crawler-test.projectium.com', - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD, @@ -220,7 +227,6 @@ module.exports = { name: 'flyer-crawler-analytics-worker-dev', watch: true, ignore_watch: ['node_modules', 'logs', '*.log', 'flyer-images', '.git'], - // Inherit secrets from the deployment environment DB_HOST: process.env.DB_HOST, DB_USER: process.env.DB_USER, DB_PASSWORD: process.env.DB_PASSWORD,