Skip to content

Commit

Permalink
fix(risedev): fixes and improvements for risedev-dev running rising…
Browse files Browse the repository at this point in the history
…wave commands
  • Loading branch information
BugenZhao committed Jul 9, 2024
1 parent f3fd040 commit ec6a63e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
22 changes: 19 additions & 3 deletions src/risedevtool/run_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@
echo "${@:3}"
echo "logging to $1, and status to $2"

"${@:3}" 2>&1 | tee "$1"
# Strip ANSI color codes to make the log file readable.
# trap '' INT: ignore interrupts in sed
strip_ansi() {
(trap '' INT; sed -e 's/\x1b\[[0-9;]*m//g')
}

# Run the command and log the output to both the terminal and the log file.
# tee -i: ignore interrupts in tee
RW_LOG_FORCE_COLORFUL=1 "${@:3}" 2>&1 | tee -i >(strip_ansi > "$1")

# Retrieve the return status.
RET_STATUS="${PIPESTATUS[0]}"

echo "status ${RET_STATUS}" > "$2"
# If the status file exists, write the return status to it.
#
# The status file is used to detect early exits. Once `risedev-dev` finishes launching successfully,
# it will clean up the status file, so it's safe to ignore it then.
if [ -f "$2" ]; then
echo "status ${RET_STATUS}" > "$2"
fi

# Show the return status in both outputs.
echo "$(date -u) [risedev]: Program exited with ${RET_STATUS}" >> "$1"
echo "Program exited with ${RET_STATUS}, press Ctrl+C to continue."
echo "Program exited with ${RET_STATUS}, press Ctrl+C again to close the window."

while true; do
read -r
Expand Down
6 changes: 1 addition & 5 deletions src/risedevtool/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ where
if !id.is_empty() {
self.pb.set_prefix(id.clone());
self.id = Some(id.clone());

// Remove the old status file if exists to avoid confusion.
let status_file = self.status_dir.path().join(format!("{}.status", id));
fs_err::remove_file(&status_file).ok();
self.status_file = Some(status_file);
self.status_file = Some(self.status_dir.path().join(format!("{}.status", id)));

// Remove the old log file if exists to avoid confusion.
let log_file = Path::new(&env::var("PREFIX_LOG").unwrap())
Expand Down
3 changes: 2 additions & 1 deletion src/utils/runtime/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ impl LoggerSettings {
Self {
name: name.into(),
enable_tokio_console: false,
colorful: console::colors_enabled_stderr() && console::colors_enabled(),
colorful: env_var_is_true("RW_LOG_FORCE_COLORFUL")
|| (console::colors_enabled_stderr() && console::colors_enabled()),
stderr: false,
with_thread_name: false,
targets: vec![],
Expand Down

0 comments on commit ec6a63e

Please sign in to comment.