@@ -32,6 +32,7 @@ defmodule FLAME.Terminator do
3232 single_use: false ,
3333 calls: % { } ,
3434 watchers: % { } ,
35+ paths: [ ] ,
3536 log: false ,
3637 status: nil ,
3738 failsafe_timer: nil ,
@@ -73,6 +74,10 @@ defmodule FLAME.Terminator do
7374 GenServer . call ( terminator , { :watch , pids } )
7475 end
7576
77+ def watch_path ( terminator , path ) do
78+ GenServer . call ( terminator , { :watch_path , path } )
79+ end
80+
7681 def deadline_me ( terminator , timeout ) do
7782 GenServer . call ( terminator , { :deadline , timeout } )
7883 end
@@ -263,6 +268,10 @@ defmodule FLAME.Terminator do
263268 { :reply , :ok , cancel_idle_shutdown ( state ) }
264269 end
265270
271+ def handle_call ( { :watch_path , path } , _from , % Terminator { watchers: paths } = state ) do
272+ { :reply , :ok , % { state | paths: [ path | paths ] } }
273+ end
274+
266275 def handle_call ( :system_shutdown , _from , % Terminator { } = state ) do
267276 { :reply , :ok ,
268277 system_stop ( state , "system shutdown instructed from parent #{ inspect ( state . parent . pid ) } " ) }
@@ -288,13 +297,22 @@ defmodule FLAME.Terminator do
288297 { :reply , :ok , schedule_idle_shutdown ( new_state ) }
289298 end
290299
300+ defp clean_up_paths ( paths ) do
301+ for path <- paths do
302+ File . rm_rf ( path )
303+ end
304+ end
305+
291306 @ impl true
292307 def terminate ( _reason , % Terminator { } = state ) do
293308 state =
294309 state
295310 |> cancel_idle_shutdown ( )
296311 |> system_stop ( "terminating" )
297312
313+ # clean up any paths that were watched before waiting to not be killed
314+ clean_up_paths ( state . paths )
315+
298316 # supervisor will force kill us if we take longer than configured shutdown_timeout
299317 Enum . each ( state . calls , fn
300318 # skip callers that placed a child since they are on the remote node
0 commit comments