Cron Job - Thumbnail Maintenance?

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

Cron Job - Thumbnail Maintenance?

Post by Gryphen » Fri Jun 08, 2018 3:50 am

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: 14
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen » Sat Jun 09, 2018 5:23 pm

Anyone got an idea on how to do it?

User avatar
onli
Regular
Posts: 2115
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli » Sat Jun 09, 2018 5:32 pm

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: 14
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen » Sun Jun 10, 2018 1:06 am

Good idea I'll see how it uploads and see if it can be altered.

Gryphen
Regular
Posts: 14
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen » Mon Jun 11, 2018 8:58 am

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.

User avatar
onli
Regular
Posts: 2115
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli » Mon Jun 11, 2018 9:07 am

Btu the images are added to the Media Library, just without thumbnails?

Gryphen
Regular
Posts: 14
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen » Mon Jun 11, 2018 9:50 am

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

User avatar
onli
Regular
Posts: 2115
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli » Mon Jun 11, 2018 10:09 pm

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: 14
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen » Tue Jun 12, 2018 10:16 am

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 :)

User avatar
onli
Regular
Posts: 2115
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli » Tue Jun 12, 2018 3:06 pm

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: 14
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen » Wed Jun 13, 2018 4:17 am

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.

User avatar
onli
Regular
Posts: 2115
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Cron Job - Thumbnail Maintenance?

Post by onli » Wed Jun 13, 2018 9:15 am

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: 14
Joined: Sun May 21, 2017 12:53 pm

Re: Cron Job - Thumbnail Maintenance?

Post by Gryphen » Wed Jun 13, 2018 11:35 am

Thanks for your help anyway :)

Post Reply