forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement retry mechanism during yarn installation (facebook#39020)
Summary: Pull Request resolved: facebook#39020 Sometimes yarn fails to intall, we are implementing a retry mechanism ## Changelog: [Internal] - Add retry mechanism in template jobs. Reviewed By: cortinico Differential Revision: D48234860 fbshipit-source-id: ece3c40051ff143837ed79db2390fbb599fa8ae2
- Loading branch information
1 parent
623f44c
commit e7f6f07
Showing
3 changed files
with
109 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react-native | ||
*/ | ||
|
||
const {spawnSync} = require('child_process'); | ||
|
||
async function retry(command, options, maxRetries, delay, args) { | ||
for (let i = 1; i <= maxRetries; i++) { | ||
console.log(`Attempt ${i}: ${command}`); | ||
const result = spawnSync(command, args ? args : [], options); | ||
|
||
if (result.status === 0) { | ||
console.log(`Command succeeded on attempt ${i}`); | ||
return true; | ||
} | ||
|
||
console.log(`Command failed on attempt ${i}`); | ||
|
||
if (i >= maxRetries) { | ||
console.log('Maximum retries reached. Exiting.'); | ||
return false; | ||
} | ||
|
||
if (delay > 0) { | ||
console.log(`Sleeping for ${delay} seconds...`); | ||
await new Promise(resolve => setTimeout(resolve, delay)); | ||
} | ||
|
||
console.log('Retrying...'); | ||
} | ||
} | ||
|
||
module.exports = { | ||
retry, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters