| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | import { getActivePlugins, processPlaceholders } from '@page-creator/api/WPApi'; |
| 2 | 2 | import { recordPluginActivity } from '@shared/api/DataApi'; |
| 3 | +import { failedDependencies } from '@shared/lib/patterns'; | |
| 4 | +import { sleep } from '@shared/lib/utils'; | |
| 3 | 5 | |
| 4 | 6 | export const processPatterns = async (patterns) => { |
| 5 | 7 | const maxAttempts = 3; |
| 6 | 8 | const delay = 1000; // 1 second delay between retries |
| @@ -21,9 +23,12 @@ | ||
| 21 | 23 | } |
| 22 | 24 | |
| 23 | 25 | for (let attempt = 1; attempt <= maxAttempts; attempt++) { |
| 24 | 26 | try { |
| 25 | - return await processPlaceholders(patterns); | |
| 27 | + const processed = await processPlaceholders(patterns); | |
| 28 | + if (!failedDependencies(processed).length || attempt === maxAttempts) { | |
| 29 | + return processed; | |
| 30 | + } | |
| 26 | 31 | } catch (error) { |
| 27 | 32 | if (attempt === maxAttempts) { |
| 28 | 33 | console.error( |
| 29 | 34 | `Failed to process patterns after ${maxAttempts} attempts:`, |
| @@ -30,8 +35,9 @@ | ||
| 30 | 35 | error, |
| 31 | 36 | ); |
| 32 | 37 | return patterns; |
| 33 | 38 | } |
| 34 | - await new Promise((resolve) => setTimeout(resolve, delay)); | |
| 35 | 39 | } |
| 40 | + | |
| 41 | + await sleep(delay); | |
| 36 | 42 | } |
| 37 | 43 | }; |