code rewritted to modules; add local/server flags to build
This commit is contained in:
53
src/local/print/advance.rs
Normal file
53
src/local/print/advance.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use super::models::*;
|
||||
use super::printer::{spawn_print_task, start_printing_locked, begin_next_locked};
|
||||
use axum::{extract::{Path as AxumPath, State}, http::StatusCode, Json};
|
||||
|
||||
pub async fn job_advance(
|
||||
State(store): State<JobStore>,
|
||||
AxumPath(job_id): AxumPath<String>,
|
||||
) -> Result<Json<JobView>, (StatusCode, String)> {
|
||||
let (view, spawn_info) = {
|
||||
let mut m = store.lock().unwrap();
|
||||
let job = m.get_mut(&job_id).ok_or_else(|| (StatusCode::NOT_FOUND, "Задание не найдено".into()))?;
|
||||
|
||||
let si = match job.phase {
|
||||
JobPhase::WaitingStart => {
|
||||
let next_idx = 0;
|
||||
job.current = Some(next_idx);
|
||||
Some(start_printing_locked(job, next_idx))
|
||||
}
|
||||
JobPhase::AwaitingPickup => {
|
||||
let c = job.current.unwrap_or(0);
|
||||
if job.duplex_first_pass_done {
|
||||
job.duplex_first_pass_done = false;
|
||||
job.files[c].status = FileStatus::AwaitingClearOutput;
|
||||
job.phase = JobPhase::AwaitingClearOutput; None
|
||||
} else {
|
||||
job.files[c].status = FileStatus::Done;
|
||||
begin_next_locked(job, c)
|
||||
}
|
||||
}
|
||||
JobPhase::AwaitingClearOutput => {
|
||||
let c = job.current.unwrap_or(0);
|
||||
job.files[c].status = FileStatus::AwaitingFlip;
|
||||
job.phase = JobPhase::AwaitingFlip; None
|
||||
}
|
||||
JobPhase::AwaitingFlip => {
|
||||
let c = job.current.unwrap();
|
||||
job.files[c].status = FileStatus::Printing;
|
||||
job.phase = JobPhase::Printing;
|
||||
Some(SpawnInfo {
|
||||
job_id: job.id.clone(), idx: c,
|
||||
path: job.files[c].path.to_path_buf(),
|
||||
settings: job.files[c].settings.clone(),
|
||||
is_second_pass: true,
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
(job.view(), si)
|
||||
};
|
||||
|
||||
if let Some(si) = spawn_info { spawn_print_task(store.clone(), si); }
|
||||
Ok(Json(view))
|
||||
}
|
||||
Reference in New Issue
Block a user