Skip to content
Snippets Groups Projects
Commit 14edcb7d authored by Benjamin Wingfield's avatar Benjamin Wingfield
Browse files

run sbatch

parent 2e245fb4
No related branches found
No related tags found
No related merge requests found
use std::process::Command;
use log::info;
use rusqlite::Connection;
use crate::db::job::state::JobState;
use crate::slurm::job::JobPath;
use crate::slurm::job_request::JobRequest;
impl JobRequest {
......@@ -10,8 +12,11 @@ impl JobRequest {
self.update(conn, state);
}
pub fn submit(&self, conn: &Connection) {
pub fn submit(&self, conn: &Connection, job: JobPath) {
let job_id = self.run_sbatch(job);
info!("SLURM job id: {job_id}");
let state = JobState::Submitted;
// todo: store SLURM job id in table too
self.update(conn, state);
}
......@@ -26,4 +31,19 @@ impl JobRequest {
&[(id.as_str())],
).expect("Update job status to {col}");
}
fn run_sbatch(&self, job_path: JobPath) -> String {
let wd = job_path.path.parent().unwrap();
let output = Command::new("sbatch")
.arg("--parsable")
.arg("--output")
.arg(wd)
.arg("--error")
.arg(wd)
.arg(job_path.path)
.output()
.expect("sbatch");
String::from_utf8(output.stdout).expect("job id")
}
}
......@@ -75,8 +75,7 @@ async fn main() {
let job_path = job.create(&wd);
if !args.dry_run {
job.stage(&conn);
// todo: sbatch this path
info!("{}", job_path.path.display())
job.submit(&conn, job_path);
} else {
info!("--dry-run set, not submitting job to slurm");
}
......
......@@ -2,6 +2,7 @@ use std::{fs, io};
use std::fs::OpenOptions;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
use chrono::Utc;
use log::{info, warn};
......@@ -11,7 +12,9 @@ use tinytemplate::TinyTemplate;
use crate::slurm::job_request::{JobRequest, NxfParamsFile, PipelineParam, TargetGenome};
use crate::WorkingDirectory;
pub struct JobPath { pub path: PathBuf }
pub struct JobPath {
pub path: PathBuf,
}
impl JobRequest {
pub fn create(&self, wd: &WorkingDirectory) -> JobPath {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment