From 76f13ec04e3d982f895d35eaf0084fb62e835089 Mon Sep 17 00:00:00 2001 From: Arne Beer Date: Tue, 15 Oct 2024 19:26:06 +0200 Subject: [PATCH] fix: enqueue response --- .../daemon/network/message_handler/enqueue.rs | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/pueue/src/daemon/network/message_handler/enqueue.rs b/pueue/src/daemon/network/message_handler/enqueue.rs index e3d8c72c..03e77f7b 100644 --- a/pueue/src/daemon/network/message_handler/enqueue.rs +++ b/pueue/src/daemon/network/message_handler/enqueue.rs @@ -1,6 +1,10 @@ use chrono::Local; use pueue_lib::{ - network::message::*, settings::Settings, state::SharedState, success_msg, task::TaskStatus, + network::message::*, + settings::Settings, + state::SharedState, + success_msg, + task::{Task, TaskStatus}, }; use crate::daemon::network::response_helper::*; @@ -73,6 +77,19 @@ pub fn enqueue(settings: &Settings, state: &SharedState, message: EnqueueMessage } } + let matching_function = if message.enqueue_at.is_some() { + |task: &Task| { + matches!( + task.status, + TaskStatus::Stashed { + enqueue_at: Some(_), + } + ) + } + } else { + |task: &Task| matches!(task.status, TaskStatus::Queued { .. }) + }; + // Construct a response depending on the selected tasks. if let Some(enqueue_at) = &message.enqueue_at { let enqueue_at = format_datetime(settings, enqueue_at); @@ -81,12 +98,7 @@ pub fn enqueue(settings: &Settings, state: &SharedState, message: EnqueueMessage TaskSelection::TaskIds(task_ids) => task_action_response_helper( &format!("Stashed tasks will be enqueued at {enqueue_at}"), task_ids.clone(), - |task| { - matches!( - task.status, - TaskStatus::Stashed { .. } | TaskStatus::Locked { .. } - ) - }, + matching_function, &state, ), TaskSelection::Group(group) => { @@ -101,12 +113,7 @@ pub fn enqueue(settings: &Settings, state: &SharedState, message: EnqueueMessage TaskSelection::TaskIds(task_ids) => task_action_response_helper( "Stashed tasks have been enqueued", task_ids.clone(), - |task| { - matches!( - task.status, - TaskStatus::Stashed { .. } | TaskStatus::Locked { .. } - ) - }, + matching_function, &state, ), TaskSelection::Group(group) => {