Skip to content

Commit

Permalink
feat(config): add serialization interval configuration (#2923)
Browse files Browse the repository at this point in the history
* add serialization interval configuration

* fix e2e tests

* fix e2e tests
  • Loading branch information
imsnif authored Nov 10, 2023
1 parent e55cd36 commit 3b4a355
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/tests/e2e/remote_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn start_zellij_mirrored_session(channel: &mut ssh2::Channel) {
channel
.write_all(
format!(
"{} {} --session {} --data-dir {} options --mirror-session true\n",
"{} {} --session {} --data-dir {} options --mirror-session true --serialization-interval 1\n",
SET_ENV_VARIABLES, ZELLIJ_EXECUTABLE_LOCATION, SESSION_NAME, ZELLIJ_DATA_DIR
)
.as_bytes(),
Expand All @@ -107,7 +107,7 @@ fn start_zellij_mirrored_session_with_layout(channel: &mut ssh2::Channel, layout
channel
.write_all(
format!(
"{} {} --session {} --data-dir {} --layout {} options --mirror-session true\n",
"{} {} --session {} --data-dir {} --layout {} options --mirror-session true --serialization-interval 1\n",
SET_ENV_VARIABLES,
ZELLIJ_EXECUTABLE_LOCATION,
SESSION_NAME,
Expand All @@ -129,7 +129,7 @@ fn start_zellij_mirrored_session_with_layout_and_viewport_serialization(
channel
.write_all(
format!(
"{} {} --session {} --data-dir {} --layout {} options --mirror-session true --serialize-pane-viewport true\n",
"{} {} --session {} --data-dir {} --layout {} options --mirror-session true --serialize-pane-viewport true --serialization-interval 1\n",
SET_ENV_VARIABLES,
ZELLIJ_EXECUTABLE_LOCATION,
SESSION_NAME,
Expand Down
15 changes: 11 additions & 4 deletions zellij-server/src/background_jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,20 @@ impl From<&BackgroundJob> for BackgroundJobContext {

static FLASH_DURATION_MS: u64 = 1000;
static PLUGIN_ANIMATION_OFFSET_DURATION_MD: u64 = 500;
static SESSION_READ_DURATION: u64 = 1000;
static SESSION_READ_DURATION: u64 = 60000;

pub(crate) fn background_jobs_main(bus: Bus<BackgroundJob>) -> Result<()> {
pub(crate) fn background_jobs_main(
bus: Bus<BackgroundJob>,
serialization_interval: Option<u64>,
) -> Result<()> {
let err_context = || "failed to write to pty".to_string();
let mut running_jobs: HashMap<BackgroundJob, Instant> = HashMap::new();
let mut loading_plugins: HashMap<u32, Arc<AtomicBool>> = HashMap::new(); // u32 - plugin_id
let current_session_name = Arc::new(Mutex::new(String::default()));
let current_session_info = Arc::new(Mutex::new(SessionInfo::default()));
let current_session_layout = Arc::new(Mutex::new((String::new(), BTreeMap::new())));
let serialization_interval = serialization_interval.map(|s| s * 1000); // convert to
// milliseconds

loop {
let (event, mut err_ctx) = bus.recv().with_context(err_context)?;
Expand Down Expand Up @@ -181,8 +186,10 @@ pub(crate) fn background_jobs_main(bus: Bus<BackgroundJob>) -> Result<()> {
resurrectable_sessions,
));
let _ = senders.send_to_screen(ScreenInstruction::DumpLayoutToHd);
task::sleep(std::time::Duration::from_millis(SESSION_READ_DURATION))
.await;
task::sleep(std::time::Duration::from_millis(
serialization_interval.unwrap_or(SESSION_READ_DURATION),
))
.await;
}
}
});
Expand Down
4 changes: 3 additions & 1 deletion zellij-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,8 @@ fn init_session(
arrow_fonts: config_options.simplified_ui.unwrap_or_default(),
};

let serialization_interval = config_options.serialization_interval;

let default_shell = config_options.default_shell.clone().map(|command| {
TerminalAction::RunCommand(RunCommand {
command,
Expand Down Expand Up @@ -885,7 +887,7 @@ fn init_session(
None,
Some(os_input.clone()),
);
|| background_jobs_main(background_jobs_bus).fatal()
move || background_jobs_main(background_jobs_bus, serialization_interval).fatal()
})
.unwrap();

Expand Down
9 changes: 9 additions & 0 deletions zellij-utils/src/input/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ pub struct Options {
#[clap(long, value_parser)]
#[serde(default)]
pub styled_underlines: Option<bool>,

/// The interval at which to serialize sessions for resurrection (in seconds)
#[clap(long, value_parser)]
pub serialization_interval: Option<u64>,
}

#[derive(ArgEnum, Deserialize, Serialize, Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -218,6 +222,7 @@ impl Options {
.scrollback_lines_to_serialize
.or(self.scrollback_lines_to_serialize);
let styled_underlines = other.styled_underlines.or(self.styled_underlines);
let serialization_interval = other.serialization_interval.or(self.serialization_interval);

Options {
simplified_ui,
Expand All @@ -244,6 +249,7 @@ impl Options {
serialize_pane_viewport,
scrollback_lines_to_serialize,
styled_underlines,
serialization_interval,
}
}

Expand Down Expand Up @@ -295,6 +301,7 @@ impl Options {
.scrollback_lines_to_serialize
.or_else(|| self.scrollback_lines_to_serialize.clone());
let styled_underlines = other.styled_underlines.or(self.styled_underlines);
let serialization_interval = other.serialization_interval.or(self.serialization_interval);

Options {
simplified_ui,
Expand All @@ -321,6 +328,7 @@ impl Options {
serialize_pane_viewport,
scrollback_lines_to_serialize,
styled_underlines,
serialization_interval,
}
}

Expand Down Expand Up @@ -384,6 +392,7 @@ impl From<CliOptions> for Options {
serialize_pane_viewport: opts.serialize_pane_viewport,
scrollback_lines_to_serialize: opts.scrollback_lines_to_serialize,
styled_underlines: opts.styled_underlines,
serialization_interval: opts.serialization_interval,
..Default::default()
}
}
Expand Down
4 changes: 4 additions & 0 deletions zellij-utils/src/kdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,9 @@ impl Options {
let styled_underlines =
kdl_property_first_arg_as_bool_or_error!(kdl_options, "styled_underlines")
.map(|(v, _)| v);
let serialization_interval =
kdl_property_first_arg_as_i64_or_error!(kdl_options, "serialization_interval")
.map(|(scroll_buffer_size, _entry)| scroll_buffer_size as u64);
Ok(Options {
simplified_ui,
theme,
Expand All @@ -1505,6 +1508,7 @@ impl Options {
serialize_pane_viewport,
scrollback_lines_to_serialize,
styled_underlines,
serialization_interval,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 686
expression: "format!(\"{:#?}\", options)"
---
Options {
Expand Down Expand Up @@ -29,4 +30,5 @@ Options {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 714
expression: "format!(\"{:#?}\", options)"
---
Options {
Expand Down Expand Up @@ -29,4 +30,5 @@ Options {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 673
expression: "format!(\"{:#?}\", options)"
---
Options {
Expand Down Expand Up @@ -27,4 +28,5 @@ Options {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 671
expression: "format!(\"{:#?}\", config)"
---
Config {
Expand Down Expand Up @@ -3592,6 +3593,7 @@ Config {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
},
themes: {},
plugins: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 729
expression: "format!(\"{:#?}\", config)"
---
Config {
Expand Down Expand Up @@ -3592,6 +3593,7 @@ Config {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
},
themes: {},
plugins: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 785
expression: "format!(\"{:#?}\", config)"
---
Config {
Expand Down Expand Up @@ -85,6 +86,7 @@ Config {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
},
themes: {},
plugins: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 696
expression: "format!(\"{:#?}\", options)"
---
Options {
Expand Down Expand Up @@ -29,4 +30,5 @@ Options {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 757
expression: "format!(\"{:#?}\", config)"
---
Config {
Expand Down Expand Up @@ -3592,6 +3593,7 @@ Config {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
},
themes: {},
plugins: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 771
expression: "format!(\"{:#?}\", config)"
---
Config {
Expand Down Expand Up @@ -3592,6 +3593,7 @@ Config {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
},
themes: {
"other-theme-from-config": Theme {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: zellij-utils/src/setup.rs
assertion_line: 743
expression: "format!(\"{:#?}\", config)"
---
Config {
Expand Down Expand Up @@ -3592,6 +3593,7 @@ Config {
serialize_pane_viewport: None,
scrollback_lines_to_serialize: None,
styled_underlines: None,
serialization_interval: None,
},
themes: {},
plugins: {
Expand Down

0 comments on commit 3b4a355

Please sign in to comment.