ferranfg / midjourney-discord-api-php

Generate images using Midjourney Bot through the Discord API.
https://ferranfigueredo.com
MIT License
135 stars 35 forks source link

Add timeout to photo upscaling process #32

Closed noatudor closed 7 months ago

noatudor commented 7 months ago

Add timeout to photo upscaling process

In this Pull Request, I have addressed an issue where the application could potentially hang indefinitely during the photo upscaling process.

Previously, the getUpscale function was invoked within a while loop without any timeout mechanism. If getUpscale persistently returned null (in cases where the upscaling process fails), the loop wouldn't terminate, causing the application to stay in waiting indefinitely.

To resolve this, I've introduced a startTime variable and a max_time_to_find_upscaled_link to create a maximum execution time for the upscaling process.

Now, when the getUpscale function fails to find a non-null upscaled_photo_url within the specified max_time_to_find_upscaled_link, it throws an Exception and gracefully exits, thereby allowing the rest of the application to continue its operation.

This change enhances the robustness of the application by ensuring that a setback in the upscaling process doesn't halt the completion of the entire script.