Skip to content

Commit

Permalink
retry support
Browse files Browse the repository at this point in the history
  • Loading branch information
imzlh committed Aug 4, 2024
1 parent badcca8 commit d1c80d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for(const arch in CC){
run(`cp -r ~/alist/.git .`);

// 开始编译
const addition = `X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=${new Date().toISOString()}'
const addition = `-X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=${new Date().toISOString()}'
-X 'github.com/alist-org/alist/v3/internal/conf.GoVersion=${
parseFloat(runWithOutput('go version').split('go version ')[1] || '0.1')
}'
Expand Down
14 changes: 10 additions & 4 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ export function cd(dir: string){
}

export async function wget(url: string, saveAs: string){
const fe = await fetch(url),
file = await Deno.open(saveAs, {createNew: true, read: false, write: true});
if(!fe.ok) throw new Error(`Failed to fetch ${url}`);
await fe.body!.pipeTo(file.writable);
for(let i = 0; i < 3; i++) try{
const fe = await fetch(url),
file = await Deno.open(saveAs, {createNew: true, read: false, write: true});
if(!fe.ok) throw new Error(`Failed to fetch ${url}`);
await fe.body!.pipeTo(file.writable);
}catch(e){
if(i === 2) throw new Error(`Failed to download ${url} after 3 retries: ${e.message}`);
console.warn(`Failed to download ${url}(retry ${i+1}/3): ${e.message}`);
await new Promise(resolve => setTimeout(resolve, 5000));
}
}

0 comments on commit d1c80d1

Please sign in to comment.