Skip to content

Commit

Permalink
Merge pull request #66 from eed3si9n/wip/retry
Browse files Browse the repository at this point in the history
Retry 5 times
  • Loading branch information
eed3si9n authored Apr 2, 2021
2 parents c81a04f + abb9d06 commit 214df1e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ case class ExportCommand(
lintCommand: LintCommand = LintCommand(),
@Description("Retry limit when fetching a file.")
@ParseAsNumber
retryCount: Int = 2,
retryCount: Int = 5,
@Description("Number of parallel resolves and downloads.")
@ParseAsNumber
parallel: Int = 4,
Expand Down Expand Up @@ -401,7 +401,8 @@ case class ExportCommand(
dep,
cache,
progressBar,
cdep
cdep,
retryCount
)

for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import coursier.cache.FileCache
import coursier.core.Dependency
import coursier.core.Module
import coursier.core.Reconciliation
import coursier.core.Resolution
import coursier.params.ResolutionParams
import coursier.util.ModuleMatchers
import coursier.util.Task
Expand Down Expand Up @@ -98,7 +99,8 @@ final case class ThirdpartyConfig(
dep: DependencyConfig,
cache: FileCache[Task],
progressBar: ResolveProgressRenderer,
cdep: Dependency
cdep: Dependency,
retryCount: Int
): Result[Task[Result[DependencyResolution]]] =
Result.fromResults(decodeForceVersions(dep)).map { decodedForceVersions =>
val allDependencies = for {
Expand All @@ -116,7 +118,20 @@ final case class ThirdpartyConfig(
.withRepositories(
if (repos.isEmpty) Resolve.defaultRepositories else repos
)
resolve.io.map(r => DependencyResolution(dep, r)).toResult

def retry(m: Int) =
Task.tailRecM[Int, Resolution](m) { (n: Int) =>
if (n <= 0) resolve.io.map(Right(_))
else
resolve.io.attempt map {
case Right(r) => Right(r)
case Left(e) if e.getMessage.contains("concurrent download") =>
Thread.sleep(100)
Left(n - 1)
case Left(e) => throw e
}
}
retry(retryCount).map(r => DependencyResolution(dep, r)).toResult
}

private type ForceVersionResult =
Expand Down

0 comments on commit 214df1e

Please sign in to comment.