← All changes
|
src/Agent/workflows/abilities/components/run/imagify/OptimizeMedia.jsx
+6
-2
3.2.2
→
3.2.3
View file →
| @@ -133,8 +133,9 @@ | ||
| 133 | 133 | if (!enabled || !url || !originalSize) return; |
| 134 | 134 | let live = true; |
| 135 | 135 | let timer; |
| 136 | 136 | let seenOriginal = false; |
| 137 | + let seenOtherStatus = false; | |
| 137 | 138 | const startedAt = Date.now(); |
| 138 | 139 | const check = async () => { |
| 139 | 140 | const response = await fetch(`${url}?extendify=${Date.now()}`, { |
| 140 | 141 | method: 'HEAD', |
| @@ -156,13 +157,16 @@ | ||
| 156 | 157 | |
| 157 | 158 | // The run answered at queue time, so only this reports a later failure. |
| 158 | 159 | const status = await ask(STATUS_ABILITY, JSON.parse(mediaKey)); |
| 159 | 160 | if (!live) return; |
| 160 | - if (status?.status === 'error') { | |
| 161 | + const expired = Date.now() - startedAt > GIVE_UP_MS; | |
| 162 | + // Imagify keeps an earlier failure until the queued job overwrites it. | |
| 163 | + if (status?.status === 'error' && (seenOtherStatus || expired)) { | |
| 161 | 164 | const reason = status.error_message || (await failureReason()); |
| 162 | 165 | if (!live) return; |
| 163 | 166 | return setState({ ...IDLE, checked: true, failure: reason || '' }); |
| 164 | 167 | } |
| 168 | + if (status?.status && status.status !== 'error') seenOtherStatus = true; | |
| 165 | 169 | if (status?.status === 'success' && status.optimized_size) |
| 166 | 170 | return setState({ |
| 167 | 171 | ...IDLE, |
| 168 | 172 | size: status.optimized_size, |
| @@ -175,9 +179,9 @@ | ||
| 175 | 179 | ); |
| 176 | 180 | // A hidden length leaves only the status, and it did not answer either. |
| 177 | 181 | if (!length && status?.status !== 'unoptimized') |
| 178 | 182 | return setUnwatchable(true); |
| 179 | - if (Date.now() - startedAt > GIVE_UP_MS) return setUnwatchable(true); | |
| 183 | + if (expired) return setUnwatchable(true); | |
| 180 | 184 | timer = setTimeout(check, POLL_MS); |
| 181 | 185 | }; |
| 182 | 186 | // A reload of a finished run would otherwise claim to be working first. |
| 183 | 187 | check(); |