Skip to main content

sofie_cli/
schedule_command.rs

1use std::path::Path;
2
3use crate::cargo::{self, Diagnostics};
4use crate::child_process;
5use crate::dev_command::{DEVELOPMENT, app_command};
6use crate::gen_command::{GenError, io_error};
7use crate::local_app::refuse_remote_database;
8
9/// Queues the schedule's job through the app's development binary, the only one knowing the
10/// worker's schedules; the worker `sofie dev` runs takes it next, whatever its interval.
11pub fn run_schedule(root: &Path, name: &str) -> Result<String, GenError> {
12    run_schedule_with(root, name, Diagnostics::Terminal)
13}
14
15pub(crate) fn run_schedule_with(
16    root: &Path,
17    name: &str,
18    diagnostics: Diagnostics,
19) -> Result<String, GenError> {
20    refuse_remote_database(root, "schedule run")?;
21    let executable = cargo::build(root, DEVELOPMENT, diagnostics)?;
22    let output = child_process::output(
23        diagnostics.process_group(),
24        app_command(root, &executable)?.args(["schedule", "run", name]),
25    )
26    .map_err(|source| io_error(&executable, source))?;
27    if !output.status.success() {
28        return Err(GenError::App(format!(
29            "`schedule run {name}` failed with {}: {}",
30            output.status,
31            String::from_utf8_lossy(&output.stderr).trim()
32        )));
33    }
34    let stdout = String::from_utf8_lossy(&output.stdout);
35    Ok(stdout
36        .lines()
37        .rev()
38        .find(|line| !line.trim().is_empty())
39        .unwrap_or_default()
40        .to_owned())
41}