@@ -8,16 +8,18 @@ const log = require('lambda-log');
8
8
9
9
log . info ( 'Loading function' ) ;
10
10
11
- // Create new session (spawns chromium and webdriver)
12
- $browser = chromium . createSession ( ) ;
11
+ // Create new reusable session (spawns chromium and webdriver)
12
+ if ( ! process . env . CLEAN_SESSIONS ) {
13
+ $browser = chromium . createSession ( ) ;
14
+ }
13
15
14
16
exports . handler = ( event , context , callback ) => {
15
17
context . callbackWaitsForEmptyEventLoop = false ;
16
18
17
- /* if (process.env.CLEAR_TMP ) {
19
+ if ( process . env . CLEAN_SESSIONS ) {
18
20
log . info ( 'attempting to clear /tmp directory' )
19
21
log . info ( child . execSync ( 'rm -rf /tmp/core*' ) . toString ( ) ) ;
20
- }*/
22
+ }
21
23
22
24
if ( process . env . DEBUG_ENV || process . env . SAM_LOCAL ) {
23
25
log . config . debug = true ;
@@ -41,6 +43,11 @@ exports.handler = (event, context, callback) => {
41
43
const inputBuffer = Buffer . from ( inputParam , 'base64' ) . toString ( 'utf8' ) ;
42
44
log . debug ( `Executing script "${ inputBuffer } "` ) ;
43
45
46
+ // Creates a new session on each event (instead of reusing for performance benefits)
47
+ if ( process . env . CLEAN_SESSIONS ) {
48
+ $browser = chromium . createSession ( ) ;
49
+ }
50
+
44
51
sandbox . executeScript ( inputBuffer , $browser , webdriver , function ( err ) {
45
52
if ( process . env . LOG_DEBUG ) {
46
53
log . debug ( child . execSync ( 'ps aux' ) . toString ( ) ) ;
0 commit comments