fn add_task(message: AddMessage, sender: &Sender<Message>, state: &SharedState) -> Message {
    let starting_status = if message.stashed || message.enqueue_at.is_some() {
        TaskStatus::Stashed
    } else {
        TaskStatus::Queued
    };

    let mut state = state.lock().unwrap();

    // Ensure that specified dependencies actually exist.
    let not_found: Vec<_> = message
        .dependencies
        .iter()
        .filter(|id| !state.tasks.contains_key(id))
        .collect();
    if !not_found.is_empty() {
        return create_failure_message(format!(
            "Unable to setup dependencies : task(s) {:?} not found",
            not_found
        ));
    }

    let command = if !message.ignore_aliases {
        // Check if there exists an alias for the given command
        insert_alias(message.command)
    } else {
        message.command.clone()
    };

    // Create a new task and add it to the state.
    let task = Task::new(
        command,
        message.path,
        message.envs,
        message.group,
        starting_status,
        message.enqueue_at,
        message.dependencies,
    );

    // Create a new group in case the user used a unknown group.
    if let Some(group) = &task.group {
        if state.groups.get(group).is_none() {
            return create_failure_message(format!(
                "Tried to create task with unknown group '{}'",
                group
            ));
        }
    }

    let task_id = state.add_task(task);

    // Notify the task handler, in case the client wants to start the task immediately.
    if message.start_immediately {
        sender
            .send(Message::Start(StartMessage {
                task_ids: vec![task_id],
                ..Default::default()
            }))
            .expect(SENDER_ERR);
    }
    // Create the customized response for the client.
    let message = if let Some(enqueue_at) = message.enqueue_at {
        format!(
            "New task added (id {}). It will be enqueued at {}",
            task_id,
            enqueue_at.format("%Y-%m-%d %H:%M:%S")
        )
    } else {
        format!("New task added (id {}).", task_id)
    };
    state.save();

    create_success_message(message)
}
/// Invoked when calling `pueue add`.
/// Queues a new task to the state.
/// If the start_immediately flag is set, send a StartMessage to the task handler.
Invoked when calling `pueue add`.
Queues a new task to the state.
If the start_immediately flag is set, send a StartMessage to the task handler.
Invoked when calling ` pueue add ` . Queues a new task to the state . If the start_immediately flag is set send a StartMessage to the task handler .
fn add_task(message: AddMessage, sender: &Sender<Message>, state: &SharedState) -> Message {
    let starting_status = if message.stashed || message.enqueue_at.is_some() {
        TaskStatus::Stashed
    } else {
        TaskStatus::Queued
    };
    let mut state = state.lock().unwrap();
    // Ensure that specified dependencies actually exist.
    let not_found: Vec<_> = message
        .dependencies
        .iter()
        .filter(|id| !state.tasks.contains_key(id))
        .collect();
    if !not_found.is_empty() {
        return create_failure_message(format!(
            "Unable to setup dependencies : task(s) {:?} not found",
            not_found
        ));
    }
    let command = if !message.ignore_aliases {
        // Check if there exists an alias for the given command
        insert_alias(message.command)
    } else {
        message.command.clone()
    };
    // Create a new task and add it to the state.
    let task = Task::new(
        command,
        message.path,
        message.envs,
        message.group,
        starting_status,
        message.enqueue_at,
        message.dependencies,
    );
    // Create a new group in case the user used a unknown group.
    if let Some(group) = &task.group {
        if state.groups.get(group).is_none() {
            return create_failure_message(format!(
                "Tried to create task with unknown group '{}'",
                group
            ));
        }
    }
    let task_id = state.add_task(task);
    // Notify the task handler, in case the client wants to start the task immediately.
    if message.start_immediately {
        sender
            .send(Message::Start(StartMessage {
                task_ids: vec![task_id],
                ..Default::default()
            }))
            .expect(SENDER_ERR);
    }
    // Create the customized response for the client.
    let message = if let Some(enqueue_at) = message.enqueue_at {
        format!(
            "New task added (id {}). It will be enqueued at {}",
            task_id,
            enqueue_at.format("%Y-%m-%d %H:%M:%S")
        )
    } else {
        format!("New task added (id {}).", task_id)
    };
    state.save();
    create_success_message(message)
}
fn add_task ( message : AddMessage , sender : & Sender < Message > , state : & SharedState ) -> Message { let starting_status = if message . stashed || message . enqueue_at . is_some ( ) { TaskStatus :: Stashed } else { TaskStatus :: Queued } ; let mut state = state . lock ( ) . unwrap ( ) ; // Ensure that specified dependencies actually exist. let not_found : Vec < _ > = message . dependencies . iter ( ) . filter ( | id | ! state . tasks . contains_key ( id ) ) . collect ( ) ; if ! not_found . is_empty ( ) { return create_failure_message ( format ! ( " " not_found ) ) ; } let command = if ! message . ignore_aliases { // Check if there exists an alias for the given command insert_alias ( message . command ) } else { message . command . clone ( ) } ; // Create a new task and add it to the state. let task = Task :: new ( command , message . path , message . envs , message . group , starting_status , message . enqueue_at , message . dependencies , ) ; // Create a new group in case the user used a unknown group. if let Some ( group ) = & task . group { if state . groups . get ( group ) . is_none ( ) { return create_failure_message ( format ! ( " " group ) ) ; } } let task_id = state . add_task ( task ) ; // Notify the task handler, in case the client wants to start the task immediately. if message . start_immediately { sender . send ( Message :: Start ( StartMessage { task_ids : vec ! [ task_id ] , .. Default :: default ( ) } ) ) . expect ( SENDER_ERR ) ; } // Create the customized response for the client. let message = if let Some ( enqueue_at ) = message . enqueue_at { format ! ( " " task_id enqueue_at format ( " " ) ) } else { format ! ( " " task_id ) } ; state . save ( ) ; create_success_message ( message ) }
Invoked when calling `pueue add`.
Invoked when calling ` pueue add ` .
message
AddMessage
sender
&Sender<Message>
state
&SharedState