-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add flag to execute scripts in parallel w.r.t. chains #203
Conversation
function saveConfig(config, env) { | ||
writeJSON(config, `${__dirname}/../axelar-chains-config/info/${env}.json`); | ||
} | ||
|
||
function saveParallelExecutionConfig(config, env, chain) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the implementation of this function is not tied to a notion of parallel execution, so the naming isn't quite right. Furthermore, it's pretty much the same as existing functions. So instead of a new helper, generalize loadConfig
/saveConfig
to take a filename
/relative path
. It can default to null meaning the current setting, but otherwise allows customizing the name. Using a different info directory is confusing as well since it's still saving the config.
@@ -852,6 +861,73 @@ const mainProcessor = async (options, processCommand, save = true, catchErr = fa | |||
} | |||
} | |||
|
|||
if (options.parallel && chains.length > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid making functions so complex. Use clear and concise helper functions to organize the code
let chainCommandIndex = -1; | ||
let skipPrompt = false; | ||
|
||
for (let commandIndex = 0; commandIndex < cmds.length; commandIndex++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a weird way to run it parallely (like what you'd need to do in bash). Why not run processCommand
without an await
for each chain and wait at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine it was to separate stdout capture between parallel runs. I'm wondering if we can capture the console.log separately or reassign .log field to something that stores the output in a list so we can output, or use a process library to do the above more cleanly. If there's no good way to do this in JS, then we can do the above but refactor it to make it cleaner
|
||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't see a need for separate code like above to handle parallel execution. Create a chainProcessor function that handles most of the for
loop body. Depending on sequential/parallel mode, it can be run with an await or the promise can be collected (or if needed using an exec in the chainProcessor function), and we await at the end.
To deal with configs in parallel mode, you can give a copy of it to each call so they don't write to the same object. And then you can merge the chain specific changes at the end. No need to save configs separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An initial complex solution is usually not the right one, I recommend spending more time to come up with a more elegant approach and discuss it during syncs if needed, otherwise codebase can easily become unmaintainable.
https://axelarnetwork.atlassian.net/browse/AXE-3324
https://axelarnetwork.atlassian.net/browse/AXE-4177