Skip to content

Commit 660180b

Browse files
authored
Merge pull request #240 from serokell/rvem/make-wait-activation-timeout-configurable
[Chore] Make activation wait timeout configurable
2 parents d507370 + 50d640f commit 660180b

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

interface.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"confirmTimeout": {
3131
"type": "integer"
3232
},
33+
"activationTimeout": {
34+
"type": "integer"
35+
},
3336
"tempPath": {
3437
"type": "string"
3538
}

src/bin/activate.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ struct WaitOpts {
101101
/// Path for any temporary files that may be needed during activation
102102
#[clap(long)]
103103
temp_path: PathBuf,
104+
105+
/// Timeout to wait for activation
106+
#[clap(long)]
107+
activation_timeout: Option<u16>,
104108
}
105109

106110
/// Revoke profile activation
@@ -319,7 +323,7 @@ pub enum WaitError {
319323
#[error("Error waiting for activation: {0}")]
320324
Waiting(#[from] DangerZoneError),
321325
}
322-
pub async fn wait(temp_path: PathBuf, closure: String) -> Result<(), WaitError> {
326+
pub async fn wait(temp_path: PathBuf, closure: String, activation_timeout: Option<u16>) -> Result<(), WaitError> {
323327
let lock_path = deploy::make_lock_path(&temp_path, &closure);
324328

325329
let (created, done) = mpsc::channel(1);
@@ -359,7 +363,7 @@ pub async fn wait(temp_path: PathBuf, closure: String) -> Result<(), WaitError>
359363
return Ok(());
360364
}
361365

362-
danger_zone(done, 240).await?;
366+
danger_zone(done, activation_timeout.unwrap_or(240)).await?;
363367

364368
info!("Found canary file, done waiting!");
365369

@@ -575,7 +579,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
575579
.await
576580
.map_err(|x| Box::new(x) as Box<dyn std::error::Error>),
577581

578-
SubCommand::Wait(wait_opts) => wait(wait_opts.temp_path, wait_opts.closure)
582+
SubCommand::Wait(wait_opts) => wait(wait_opts.temp_path, wait_opts.closure, wait_opts.activation_timeout)
579583
.await
580584
.map_err(|x| Box::new(x) as Box<dyn std::error::Error>),
581585

src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ pub struct Opts {
8585
/// How long activation should wait for confirmation (if using magic-rollback)
8686
#[clap(long)]
8787
confirm_timeout: Option<u16>,
88+
/// How long we should wait for profile activation (if using magic-rollback)
89+
#[clap(long)]
90+
activation_timeout: Option<u16>,
8891
/// Where to store temporary files (only used by magic-rollback)
8992
#[clap(long)]
9093
temp_path: Option<PathBuf>,
@@ -658,6 +661,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
658661
magic_rollback: opts.magic_rollback,
659662
temp_path: opts.temp_path,
660663
confirm_timeout: opts.confirm_timeout,
664+
activation_timeout: opts.activation_timeout,
661665
dry_activate: opts.dry_activate,
662666
remote_build: opts.remote_build,
663667
sudo: opts.sudo,

src/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct GenericSettings {
2525
pub auto_rollback: Option<bool>,
2626
#[serde(rename(deserialize = "confirmTimeout"))]
2727
pub confirm_timeout: Option<u16>,
28+
#[serde(rename(deserialize = "activationTimeout"))]
29+
pub activation_timeout: Option<u16>,
2830
#[serde(rename(deserialize = "tempPath"))]
2931
pub temp_path: Option<PathBuf>,
3032
#[serde(rename(deserialize = "magicRollback"))]

src/deploy.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct WaitCommandData<'a> {
121121
sudo: &'a Option<String>,
122122
closure: &'a str,
123123
temp_path: &'a Path,
124+
activation_timeout: Option<u16>,
124125
debug_logs: bool,
125126
log_dir: Option<&'a str>,
126127
}
@@ -142,6 +143,9 @@ fn build_wait_command(data: &WaitCommandData) -> String {
142143
data.closure,
143144
data.temp_path.display(),
144145
);
146+
if let Some(activation_timeout) = data.activation_timeout {
147+
self_activate_command = format!("{} --activation-timeout {}", self_activate_command, activation_timeout);
148+
}
145149

146150
if let Some(sudo_cmd) = &data.sudo {
147151
self_activate_command = format!("{} {}", sudo_cmd, self_activate_command);
@@ -155,6 +159,7 @@ fn test_wait_command_builder() {
155159
let sudo = Some("sudo -u test".to_string());
156160
let closure = "/nix/store/blah/etc";
157161
let temp_path = Path::new("/tmp");
162+
let activation_timeout = Some(600);
158163
let debug_logs = true;
159164
let log_dir = Some("/tmp/something.txt");
160165

@@ -163,10 +168,11 @@ fn test_wait_command_builder() {
163168
sudo: &sudo,
164169
closure,
165170
temp_path,
171+
activation_timeout,
166172
debug_logs,
167173
log_dir
168174
}),
169-
"sudo -u test /nix/store/blah/etc/activate-rs --debug-logs --log-dir /tmp/something.txt wait '/nix/store/blah/etc' --temp-path '/tmp'"
175+
"sudo -u test /nix/store/blah/etc/activate-rs --debug-logs --log-dir /tmp/something.txt wait '/nix/store/blah/etc' --temp-path '/tmp' --activation-timeout 600"
170176
.to_string(),
171177
);
172178
}
@@ -328,6 +334,8 @@ pub async fn deploy_profile(
328334

329335
let confirm_timeout = deploy_data.merged_settings.confirm_timeout.unwrap_or(30);
330336

337+
let activation_timeout = deploy_data.merged_settings.activation_timeout;
338+
331339
let magic_rollback = deploy_data.merged_settings.magic_rollback.unwrap_or(true);
332340

333341
let auto_rollback = deploy_data.merged_settings.auto_rollback.unwrap_or(true);
@@ -386,6 +394,7 @@ pub async fn deploy_profile(
386394
sudo: &deploy_defs.sudo,
387395
closure: &deploy_data.profile.profile_settings.path,
388396
temp_path: temp_path,
397+
activation_timeout: activation_timeout,
389398
debug_logs: deploy_data.debug_logs,
390399
log_dir: deploy_data.log_dir,
391400
});

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub struct CmdOverrides {
163163
pub magic_rollback: Option<bool>,
164164
pub temp_path: Option<PathBuf>,
165165
pub confirm_timeout: Option<u16>,
166+
pub activation_timeout: Option<u16>,
166167
pub sudo: Option<String>,
167168
pub dry_activate: bool,
168169
pub remote_build: bool,
@@ -444,6 +445,9 @@ pub fn make_deploy_data<'a, 's>(
444445
if let Some(confirm_timeout) = cmd_overrides.confirm_timeout {
445446
merged_settings.confirm_timeout = Some(confirm_timeout);
446447
}
448+
if let Some(activation_timeout) = cmd_overrides.activation_timeout {
449+
merged_settings.activation_timeout = Some(activation_timeout);
450+
}
447451

448452
DeployData {
449453
node_name,

0 commit comments

Comments
 (0)