Execute something after the response is sent?

phoenix
troubleshooting
#1

Hi everyone,

I would like to be able to execute some code just after having sent a response.
I’m generating an image, that should be sent, removed afterwards.
If I do it on the register_before_send, it will fail because the file is streamed (using send_file).

I would like to avoid doing a send_after since I’m not really sure in how much time a file can be sent.
also, loading the image into memory is somehting I would like to avoid.

Anyone have an idea ?

Thanks !

1 Like
#2

Hey @TheSquad this question is pretty similar to Cowboy 2 - doing cleanup work after connection closes. Even if you aren’t using a temporary file, the same idea could still be used.

1 Like
#3

Hi @benwilson512, thanks for the suggestion !

I was thinking about this solution actually (monitoring the HTTP process), but I wanted to be sure that I didn’t miss some kind (Hoping) of underdog hook on Phoenix…

I really don’t want to read the file, it might be several MB…

#4

Ok, so on the advice of @benwilson512 I have ended doing a spawn on the controller with a function monitoring the process controlling the socket… as soon as I receive the {:DOWN, …} I do my stuff

#5

@TheSquad You can also check this link for a similar example:

Hope this helps,

Best regards,

Joaquin Alcerro