Page 1 of 1

Use send for file cleanup?

Posted: Wed Sep 16, 2020 11:12 pm
by thatkeith
I have a site where images can be uploaded for exif data editing. The edited image is then downloaded by the user, but this leaves the images to build up on the server. Any suggestions for how I should automate a regular cleanup? Is 'send' a viable candidate for this, when it's all executed from code embedded in an HTML page? Will variables persist?

Re: Use send for file cleanup?

Posted: Thu Sep 17, 2020 12:06 am
by ghettocottage
You could just run a simple bash command on a cron every night to clean up files older than a day. Something like:

Code: Select all

       find /path/to/your/folder/*.jpg -type f -daystart -mtime +0 -exec rm {} \;  

Re: Use send for file cleanup?

Posted: Thu Sep 17, 2020 12:14 am
by thatkeith
Good call, definitely my fallback if I can't find a LiveCode specific method. I'm rather interested to know how that might be approached in a server environment with the script embedded in a web page! :?

Re: Use send for file cleanup?

Posted: Thu Sep 17, 2020 12:49 am
by FourthWorld
CGIs are discreet processes. LC is launched by Apache, runs, returns a value, and dies with each request.

This keeps things simple and tidy, but obviates persistent processing like needing to run a periodic cleanup.

Cron is the tool of choice for periodic tasks, but if you want to clean it up with a manual trigger you could write another script for that, and it in your browser or via a button in a local LC stack with the GET command.

Re: Use send for file cleanup?

Posted: Thu Sep 17, 2020 9:19 am
by thatkeith
Gotcha. Makes perfect sense.

What I was wondering was would it (even) be possible to have the code in the web page have a 'send to handler in me in five minutes' so it would effectively do its own cleanup? How would that sit in this launch/run/die scenario? Cron is very likely the best option for this, but there are two reasons I'm pushing for a LC-based approach:
  • It could possibly be more targeted, in that it could (if a variable can be preserved across 'send') actively target only the file it just made rather than blindly removing anything – including theoretically one made just a second before the cron job ran (EDIT: "clean up files older than a day" — so that's already a non-problem. Oops! Thanks.)
  • It helps me gain a deeper understanding of using LC in this faceless environment
:)

But I'm not actually against using cron. Just exploring and feeling for logical boundaries. 8)

Re: Use send for file cleanup?

Posted: Thu Sep 17, 2020 10:11 am
by FourthWorld
You probably don't want each CGI process hanging out for five minutes.

Another option would be self-cleaning: what if each new request deleted older files from earlier requests?

Re: Use send for file cleanup?

Posted: Thu Sep 17, 2020 11:46 am
by SparkOut
Or (best of both worlds) have a separate lc script that does what you want with all the specifics of file analysis and deletion, and call that on crontab. Added advantage: call on demand using regular browser.

Re: Use send for file cleanup?

Posted: Fri Oct 16, 2020 9:03 pm
by thatkeith
I have a cron script working very well - thanks, all, for your advice! But I think I'll switch to this idea (cron running a LC stack) soon, so as you say I get the best of both worlds. 👍