/// Create and enqueue tasks from already finished tasks
/// The user can specify to immediately start the newly created tasks.
Create and enqueue tasks from already finished tasks
The user can specify to immediately start the newly created tasks.
Create and enqueue tasks from already finished tasks The user can specify to immediately start the newly created tasks .
fn restart(message: RestartMessage, sender: &Sender<Message>, state: &SharedState) -> Message {
    let response: String;
    let new_ids = {
        let mut state = state.lock().unwrap();
        let statuses = vec![TaskStatus::Done, TaskStatus::Failed, TaskStatus::Killed];
        let (matching, mismatching) = state.tasks_in_statuses(Some(message.task_ids), statuses);
        let mut new_ids = Vec::new();
        for task_id in &matching {
            let task = state.tasks.get(task_id).unwrap();
            let new_task = Task::from_task(task);
            new_ids.push(state.add_task(new_task));
        }
        // Already create the response string in here. Otherwise we would
        // need to get matching/mismatching out of this scope
        let message = "Restarted tasks";
        response = compile_task_response(message, matching, mismatching);
        new_ids
    };
    // If the restarted tasks should be started immediately, send a message
    // with the new task ids to the task handler.
    if message.start_immediately {
        let start_message = StartMessage { task_ids: new_ids };
        sender
            .send(Message::Start(start_message))
            .expect(SENDER_ERR);
    }
    return create_success_message(response);
}
fn restart ( message : RestartMessage , sender : & Sender < Message > , state : & SharedState ) -> Message { let response : String ; let new_ids = { let mut state = state . lock ( ) . unwrap ( ) ; let statuses = vec ! [ TaskStatus Done TaskStatus Failed TaskStatus Killed ] ; let ( matching , mismatching ) = state . tasks_in_statuses ( Some ( message . task_ids ) , statuses ) ; let mut new_ids = Vec :: new ( ) ; for task_id in & matching { let task = state . tasks . get ( task_id ) . unwrap ( ) ; let new_task = Task :: from_task ( task ) ; new_ids . push ( state . add_task ( new_task ) ) ; } // Already create the response string in here. Otherwise we would // need to get matching/mismatching out of this scope let message = " " ; response = compile_task_response ( message , matching , mismatching ) ; new_ids } ; // If the restarted tasks should be started immediately, send a message // with the new task ids to the task handler. if message . start_immediately { let start_message = StartMessage { task_ids : new_ids } ; sender . send ( Message :: Start ( start_message ) ) . expect ( SENDER_ERR ) ; } return create_success_message ( response ) ; }
Create and enqueue tasks from already finished tasks
The user can specify to immediately start the newly created tasks.
Create and enqueue tasks from already finished tasks The user can specify to immediately start the newly created tasks .
message
RestartMessage
sender
&Sender<Message>
state
&SharedState