[web-devel] Generating, serving, and deleting temporary files with Wai/Yesod

Matt Brown matt at softmechanics.net
Fri Oct 22 20:21:06 CEST 2010


Hello all,

I've been experimenting with generating graphs from log files using
timeplot and serving them with yesod.  Each generated graph is only
served once, so I need a way to clean them up.  A cron job would be
ok, but it's one more thing I'd have to remember to do, and I'm lazy.

Instead, I'd like to pass a "clean up action" to the enumerator
sending the file, to be performed after EOF is reached.  For most
files, this would just close the handle.  For temp files, it would
also delete the file.  Here's the gist of it:
http://gist.github.com/640902

The first revision defines a monolithic fromTempFile :: FilePath ->
Enumerator.  The second imports a factored version from
Network.Wai.Handler (see my wai commit:
http://github.com/softmechanics/wai/commit/2cb5ea47ca458f4b91a73e01a1dd0a29e84e001e).
Not sure wai is the place for it.  Perhaps wai-extra would be a better?

Does this seem like a good approach?

Regards,
-matt


More information about the web-devel mailing list