Cron Job - Thumbnail Maintenance?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Cron Job - Thumbnail Maintenance?

Post by Gryphen »

Hi Guys,

I'm getting everything slowly lined up to automate most of the things I want to try to get done with my blog whilst I am travelling.

One of the things I've found is that if I use the Wordpress App on my iPhone or iPad it uploads the pictures, but the Media library of course doesn't automatically create thumbnails etc (as the popfetcher plugin does) so is there a way to run a maintenance task as a Cron Job? I was thinking of choosing the early hours of the morning to run a maintenance task to "rebuild thumbs" but "Keep all existing thumbnails" to correct this.

Part of the reason is I also use the gallery plugin, so it misses out on images if I don't refresh the thumbs etc.

Any assistance would be greatly appreciated.

p.s I'm not adept at this by any stretch of the imagination, and I only have rudimentary knowledge of what I'm trying to do, so the better detailed the description the better :)
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen »

Anyone got an idea on how to do it?
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli »

I'm not familiar with the cron plugin, but I thought you'd need to write a plugin of your own that then calls the media thumbnail rebuild function and that hooks into the cron plugin. Garvin could probably give you better guidance there. Sounds complicated to me though.

Maybe it would be a better idea to solve the problem at its core. Do you know why the wordpress app/the XMLRPC plugin does not create the thumbails? That might be a bug.
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen »

Good idea I'll see how it uploads and see if it can be altered.
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen »

Seems the app uploads a post as an article(serendipity) other than that there is no means to alter it... but as I expect on an Apple device.


So I'll still be looking for a way to call the maintenance taks via a cron job.
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli »

Btu the images are added to the Media Library, just without thumbnails?
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen »

Yep, they don't get processed via the xmlrpc function, I know that when I use popfetcher it processes them, I can see that by monitoring the processes etc. the xmlrpc seems to direct load the images and link to those
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli »

So, I had a look into the code. I think https://github.com/s9y/additional_plugi ... .php#L1673 is the function that handles image/file uploads. And indeed that just writes the file onto the disk. I think it would be possible to add a call to serendipity_makeThumbnail here. That would be something like

Code: Select all

$path = $serendipity['baseURL'] . $serendipity['uploadHTTPPath'] . $serendipity['xmlrpc_uploadreldir'] . $struct['name'];
universal_debug("url: " . $path);
serendipity_makeThumbnail($struct['name'], $serendipity['xmlrpc_uploadreldir']);
return new XML_RPC_Response(new XML_RPC_Value(array('url' => new XML_RPC_Value($path, 'string')), 'struct'));
But I'm not sure, might need a bit of debugging to make it work, to find the right parameters, and some testing to make sure it is not harmful.
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen »

Well that is closer...

serendipity_makeThumbnail($struct['name'], $serendipity['xmlrpc_uploadreldir']);

That works to kick off the thumbnail creation, though I suspect it went to kick off a scan of all thumbnails and make any new ones, just based upon the time it took to finish the convert.

The issue now though is that it takes so long to run that the app on the phone fails to post, it actually uploads the pictures, creates the thumbs, but the thumb creation takes longer than the timeout for the app to post (I suspect that is built into the app on the iPhone) and therefore reports it fails to upload, and doesn't create the post.

It's closer though :)
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli »

That's strange, the function really only creates thumbnail for one image. And that should not take long. It took longer than 3 or 5 seconds?
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen »

I wish, the box it runs on is an old Readynas Duo Nv1, SPARC, using Debian Sarge and is slow to process an image and create a thumbnail. The process of uploading an image and generating a thumbnail can take about 7 minutes, the uploading of the image is quick, using convert to process the image and create the thumbnail is slow.

If I use email and popfetcher it is all in the background and so no impact, but using xmlrpc is the issue with the app timing out now, might be easier just to leave it as is.
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli »

Wow. Okay, then this won't work for you - but it should work for virtually every other user ;) And it is more correct to create the thumbnail here, this seems to just be missing. I'm thinking of adding it to the plugin but making it deactivable for edge cases like your server.

I'd move it to a worker queue to have it run in the background, but we don't have nothing like that, and can't add it without introducing a big dependency like redis.
Gryphen
Regular
Posts: 31
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen »

Thanks for your help anyway :)
Leboeuf
Posts: 1
Joined: Thu Jul 19, 2018 12:02 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Leboeuf »

Grypheen wrote: Wed Jun 13, 2018 11:35 am Thanks for your help with these awesome recurve bows anyway :)
I think that's a great idea, adding it to the plugin and making it optional. When might we see this feature, Onli?
Last edited by Leboeuf on Mon Apr 24, 2023 2:30 pm, edited 5 times in total.
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli »

Okay, sure. I added it to this new version, could you test it?
Attachments
serendipity_event_xmlrpc.tar.gz
(46.03 KiB) Downloaded 236 times
Post Reply