echogarden 0.11.19 → 0.11.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,8 @@ import { inspect } from 'node:util'
4
4
 
5
5
  import { RandomGenerator } from './RandomGenerator.js'
6
6
  import { randomUUID, randomBytes } from 'node:crypto'
7
+ import { Logger } from './Logger.js'
8
+ import chalk from 'chalk'
7
9
 
8
10
  const log = logToStderr
9
11
 
@@ -445,9 +447,9 @@ export function splitFilenameOnExtendedExtension(filenameWithExtension: string)
445
447
  splitPoint = i
446
448
 
447
449
  continue
448
- } else {
449
- break
450
- }
450
+ } else {
451
+ break
452
+ }
451
453
  }
452
454
  }
453
455
 
@@ -566,9 +568,41 @@ export function getConsecutiveRepetitionScoreRelativeToFirstSubstring(tokens: st
566
568
  export async function resolveModuleScriptPath(moduleName: string) {
567
569
  const { resolve } = await import('import-meta-resolve')
568
570
 
569
- const scriptPath = await resolve(moduleName, import.meta.url)
571
+ const scriptPath = resolve(moduleName, import.meta.url)
570
572
 
571
573
  const { fileURLToPath } = await import('url')
572
574
 
573
575
  return fileURLToPath(scriptPath)
574
576
  }
577
+
578
+ export async function runOperationWithRetries<R>(
579
+ operationFunc: () => Promise<R>,
580
+ logger: Logger,
581
+ opreationName = "Operation",
582
+ delayBetweenRetries = 2000,
583
+ maxRetries = 200) {
584
+
585
+ for (let retryIndex = 1; retryIndex <= maxRetries; retryIndex++) {
586
+ try {
587
+ const result = await operationFunc()
588
+
589
+ return result
590
+ } catch (e: any) {
591
+ logger.setAsActiveLogger()
592
+
593
+ logger.logTitledMessage(`Error`, e.message, chalk.redBright)
594
+ logger.log(``)
595
+ logger.logTitledMessage(`${opreationName} failed`, `Trying again in ${delayBetweenRetries}ms..`, chalk.redBright)
596
+
597
+ await delay(delayBetweenRetries)
598
+
599
+ logger.log(``)
600
+ logger.logTitledMessage(`Starting retry attempt`, `${retryIndex} / ${maxRetries}`, chalk.yellowBright)
601
+ logger.log(``)
602
+
603
+ logger.unsetAsActiveLogger()
604
+ }
605
+ }
606
+
607
+ throw new Error(`${opreationName} failed after ${maxRetries} retry attempts`)
608
+ }