File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ PROJECT_CANIS_ALIAS=Canis
33# automatically reboot canis, if a potential memory leak has been detected,
44# or the memory usage was just way too high
55PROJECT_AUTO_RESTART = false
6- PROJECT_MAX_MEMORY = 1024 # 1GB
6+ PROJECT_THRESHOLD_MEMORY = 1024
7+ PROJECT_MAX_MEMORY = 2048 # 2GB
78
89# whether to enable debug mode
910# in debug mode, additional logging is enabled
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import path from "path";
33import crypto from "crypto" ;
44import { MessageMedia } from "whatsapp-web.js" ;
55import axios from "../axios" ;
6+ import log from "./log" ;
67
78export async function download (
89 url : string ,
@@ -20,6 +21,20 @@ export async function download(
2021
2122 try {
2223 await fs . writeFile ( tempPath , response . data , "base64" ) ;
24+
25+ // Schedule deletion after 1 minute
26+ setTimeout ( async ( ) => {
27+ try {
28+ await fs . unlink ( tempPath ) ;
29+ log . info ( "Download" , `Temporary file deleted: ${ tempPath } ` ) ;
30+ } catch ( err ) {
31+ log . error (
32+ "Download" ,
33+ `Failed to delete temp file: ${ ( err as Error ) . message } ` ,
34+ ) ;
35+ }
36+ } , 60 * 1000 ) ;
37+
2338 return MessageMedia . fromFilePath ( tempPath ) ;
2439 } catch ( err ) {
2540 throw new Error (
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export default class MemoryMonitor {
2525
2626 constructor ( {
2727 interval = 60000 ,
28- thresholdMB = 500 ,
28+ thresholdMB = 1024 ,
2929 } : MemoryMonitorOptions = { } ) {
3030 this . interval = interval ;
3131 this . thresholdMB = thresholdMB ;
Original file line number Diff line number Diff line change @@ -11,7 +11,14 @@ import "./components/process";
1111import "./components/server" ;
1212import MemoryMonitor from "./components/utils/memMonitor" ;
1313
14- const monitor = new MemoryMonitor ( { interval : 30000 } ) ;
14+ const monitor = new MemoryMonitor ( {
15+ interval : 60000 ,
16+ thresholdMB : parseInt (
17+ process . env . PROJECT_THRESHOLD_MEMORY || "1024" ,
18+ 10
19+ )
20+ } ) ;
21+
1522monitor . start ( ) ;
1623checkRequirements ( ) ;
1724
You can’t perform that action at this time.
0 commit comments