Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
--restart option added to 'yarn migrate:..' in 'ap-contacts'
Browse files Browse the repository at this point in the history
(#APm-45)
  • Loading branch information
vkonst committed Aug 31, 2020
1 parent 6885a6c commit 078ae11
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Make node.js terminate on unhandled rejections, and run "migrate"
module.exports = async () => await Promise.resolve();
module.exports.tags = ["migrate-terminate"];
module.exports.dependencies = [
"_terminate-on-rejections",
"migrate"
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Starting from v.10.20, node.js supports "--unhandled-rejections=strict" option
// This script adds similar behaviour for earlier versions

/**
* @typedef {import('./1-extend-buidler-env').BuidlerRuntimeEnvironment}
* @param {BuidlerRuntimeEnvironment} buidlerRuntime
*/
module.exports = async (buidlerRuntime) => {
const { deployments: { log }} = buidlerRuntime;

process.on('unhandledRejection', (err) => {
console.error(`${err}`);
console.error('An unhandledRejection occurred. Terminating...');
process.exit(128);
});

log('--unhandled-rejections=strict emulated');

await Promise.resolve();
}

module.exports.tags = ["_terminate-on-rejections"];
21 changes: 19 additions & 2 deletions packages/ap-contracts/scripts/deploy-contracts.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
# Usage:
# $ deploy-contracts.sh <network [--terminate-on-rejections]>

set -o errexit

Expand All @@ -11,17 +13,32 @@ grep -Eq '^(ap\-chain|goerli|kovan|rinkeby|ropsten)$' <<< "${network}" || {
exit 1
}

# by default, run migration once (do not restart if failed)
_restart=
tags="migrate"
if [ "$2" == "--restart" ]; then
# restart migration if an unhandled rejection occurs
_restart=yes
tags="migrate-terminate"
fi

echo "Deploying to ${network} ..."
while test -f "${flag}"; do
node --unhandled-rejections=strict --max-old-space-size=4096 node_modules/.bin/buidler deploy \

node --max-old-space-size=4096 node_modules/.bin/buidler deploy \
--network "${network}" \
--tags migrate \
--tags "${tags}" \
--write true \
&& {
echo "DONE successfully"
exit 0
}

[ -z "${_restart}" ] && {
echo "[!] FAILED"
exit 1
}

echo "failed. running again ..."
sleep 10
done

0 comments on commit 078ae11

Please sign in to comment.