Use send for file cleanup?

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Use send for file cleanup?

Post by thatkeith » Wed Sep 16, 2020 11:12 pm

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?
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 366
Joined: Tue Apr 10, 2012 9:18 am

Re: Use send for file cleanup?

Post by ghettocottage » Thu Sep 17, 2020 12:06 am

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 {} \;  

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Re: Use send for file cleanup?

Post by thatkeith » Thu Sep 17, 2020 12:14 am

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! :?
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Use send for file cleanup?

Post by FourthWorld » Thu Sep 17, 2020 12:49 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Re: Use send for file cleanup?

Post by thatkeith » Thu Sep 17, 2020 9:19 am

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)
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Use send for file cleanup?

Post by FourthWorld » Thu Sep 17, 2020 10:11 am

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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Use send for file cleanup?

Post by SparkOut » Thu Sep 17, 2020 11:46 am

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.

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Re: Use send for file cleanup?

Post by thatkeith » Fri Oct 16, 2020 9:03 pm

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. 👍
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

Post Reply

Return to “CGIs and the Server”