-
Notifications
You must be signed in to change notification settings - Fork 12
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
scripts start observers #178
Conversation
scripts/observers/clean.py
Outdated
|
||
try: | ||
shutil.rmtree(working_dir) | ||
print("done") |
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.
print(f"removed directory: {working_dir}")
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.
done.
scripts/observers/clean.py
Outdated
shutil.rmtree(working_dir) | ||
print("done") | ||
except: | ||
print('did nothing') |
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.
"nothing to clean" / "directory not removed"
or simply pass
.
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.
refactored
update_toml_node(node_config, shard_id) | ||
update_toml_indexer(indexer_config, shard_id) | ||
|
||
|
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.
Usually, we define a main()
, then call it at the end of the file.
Examples:
- https://github.com/ElrondNetwork/db-archive-scripts/tree/main/archive_py
- https://github.com/ElrondNetwork/elrond-sdk-images/tree/main/scripts
- https://github.com/ElrondNetwork/rosetta-docker-scripts
(optional, can also be left as it is)
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.
added main for all files
scripts/observers/config.py
Outdated
data1 = toml.load(path+"/prefs.toml") | ||
data1['config']['web-socket']['server-url'] = str(shard_id) | ||
if shard_id != METACHAIN: | ||
data1['config']['web-socket']['server-url'] = "localhost:" + str(22111+shard_id) |
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.
Is 22111
the port base? Perhaps define a constant or receive it in the env file?
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.
added a constant
scripts/observers/config.py
Outdated
|
||
def update_toml_indexer(path, shard_id): | ||
# prefs.toml | ||
data1 = toml.load(path+"/prefs.toml") |
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.
Bit of renaming: data1
vs. prefs_data
or something similar.
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.
renamed
scripts/observers/config.py
Outdated
|
||
def update_toml_indexer(path, shard_id): | ||
# prefs.toml | ||
data1 = toml.load(path+"/prefs.toml") |
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.
If path is a pathlib.Path
, then you can also use the /
operator. For example: https://github.com/ElrondNetwork/elrond-sdk-images/blob/main/scripts/build_contract_rust_within_docker.py#L104
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.
refactored.
import sys | ||
import shutil | ||
from pathlib import Path | ||
from git import Repo |
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 does not seem from the standard library. Perhaps add a requirements.txt
file and a README explanation?
For example:
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.
done
scripts/observers/config.py
Outdated
# build binary indexer | ||
print("building indexer...") | ||
os.chdir("../../cmd/elasticindexer") | ||
os.system("go build") |
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.
Usually, we favor subprocess
instead of os.system
. Example:
(rosetta-ci is a private repository)
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.
done
scripts/observers/config.py
Outdated
|
||
# prepare observers | ||
print("preparing config...") | ||
prepare_observer(0) |
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.
👍
os.chdir(working_dir_observer + "/node") | ||
command = "./node" + " --log-level *:DEBUG --no-key --log-save" | ||
# os.system("gnome-terminal 'bash -c \"" + command + ";bash\"'") | ||
os.system("screen -d -m -S obs" + str(shard_id) + " " + command) |
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.
Oh, I see, we're using screen
. Perhaps get a second opinion from @valentin-lup, if this is all right.
scripts/observers/stop.py
Outdated
@@ -0,0 +1,4 @@ | |||
import os | |||
|
|||
os.system("killall screen") |
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.
Will kill all screen
instances that the user has. Perhaps we should find another solution for this, or remove the stop.py
script in order to avoid undesired effects?
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.
changed
updatePropNFT *data.NFTDataUpdate | ||
tokenInfo *data.TokenInfo | ||
delegator *data.Delegator | ||
processed bool |
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.
move processed bool
to the last position
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.
done
scripts/observers/.env
Outdated
ELROND_GO_BRANCH="feat/altered-accounts" | ||
|
||
WORKING_DIRECTORY="IndexerObservers" | ||
OBSERVER_DIR="observer_shard_" |
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.
might rename to OBSERVER_DIR_PREFIX
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.
done
working_dir = Path(Path.home() / os.getenv('WORKING_DIRECTORY')) | ||
|
||
try: | ||
shutil.rmtree(working_dir) |
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.
use a default path for the scripts, not the user's home
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.
refactored
scripts/observers/config.py
Outdated
@@ -80,7 +80,11 @@ def prepare_observer(shard_id, working_dir, config_folder): | |||
|
|||
def main(): | |||
load_dotenv() | |||
working_dir = Path(Path.home() / os.getenv('WORKING_DIRECTORY')) | |||
working_dir_var = os.getenv('WORKING_DIRECTORY') | |||
if working_dir_var == "": |
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.
duplicated code. might extract a function an use it in the both places
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.
done
scripts/observers/start.py
Outdated
|
||
current_directory = os.getcwd() | ||
# start observer | ||
os.chdir(working_dir_observer + "/node") | ||
os.chdir(Path(working_dir_observer / "node")) |
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.
The cast to Path
is not required (here and below).
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.
removed
from dotenv import load_dotenv | ||
from utils import * |
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.
Usually, we should be importing modules without using the wildcard *
.
scripts/observers/config.py
Outdated
|
||
# build binary elrond-go | ||
print("building node...") | ||
subprocess.check_call(["go", "build"], cwd=Path(elrond_go_folder / "cmd/node")) |
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.
🚀
3fed07b
testnet
,devnet
ormainnet
based on the.env
config file