Use send for file cleanup?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 346
- Joined: Mon Mar 01, 2010 7:13 pm
- Location: London, UK
- Contact:
Use send for file cleanup?
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
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist
-
- Livecode Opensource Backer
- Posts: 366
- Joined: Tue Apr 10, 2012 9:18 am
Re: Use send for file cleanup?
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 {} \;
-
- VIP Livecode Opensource Backer
- Posts: 346
- Joined: Mon Mar 01, 2010 7:13 pm
- Location: London, UK
- Contact:
Re: Use send for file cleanup?
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
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist
-
- VIP Livecode Opensource Backer
- Posts: 9852
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Use send for file cleanup?
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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 346
- Joined: Mon Mar 01, 2010 7:13 pm
- Location: London, UK
- Contact:
Re: Use send for file cleanup?
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:
But I'm not actually against using cron. Just exploring and feeling for logical boundaries.
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.
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist
-
- VIP Livecode Opensource Backer
- Posts: 9852
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Use send for file cleanup?
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?
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Use send for file cleanup?
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.
-
- VIP Livecode Opensource Backer
- Posts: 346
- Joined: Mon Mar 01, 2010 7:13 pm
- Location: London, UK
- Contact:
Re: Use send for file cleanup?
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
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist