pub fn new(
        session: &SessionRef,
        id: TaskId,
        inputs: Vec<TaskInput>,
        outputs: Vec<DataObjectRef>,
        task_type: String,
        attributes: Attributes,
        resources: Resources,
    ) -> Result<Self> {
        assert_eq!(id.get_session_id(), session.get_id());
        let mut waiting = RcSet::new();
        for i in inputs.iter() {
            let inobj = i.object.get();
            match inobj.state {
                DataObjectState::Removed => {
                    bail!(
                        "Can't create Task {} with Finished input object {}",
                        id,
                        inobj.id
                    );
                }
                DataObjectState::Finished => {}
                DataObjectState::Unfinished => {
                    waiting.insert(i.object.clone());
                }
            }
            if inobj.id.get_session_id() != id.get_session_id() {
                bail!(
                    "Input object {} for task {} is from a different session",
                    inobj.id,
                    id
                );
            }
        }
        for out in outputs.iter() {
            let o = out.get();
            if let Some(ref prod) = o.producer {
                bail!(
                    "Object {} already has producer (task {}) when creating task {}",
                    o.id,
                    prod.get().id,
                    id
                );
            }
            if o.id.get_session_id() != id.get_session_id() {
                bail!(
                    "Output object {} for task {} is from a different session",
                    o.id,
                    id
                );
            }
        }
        let sref = TaskRef::wrap(Task {
            id: id,
            state: if waiting.is_empty() {
                TaskState::Ready
            } else {
                TaskState::NotAssigned
            },
            inputs: inputs,
            outputs: outputs.into_iter().collect(),
            waiting_for: waiting,
            assigned: None,
            scheduled: None,
            session: session.clone(),
            task_type: task_type,
            finish_hooks: Default::default(),
            attributes: attributes,
            resources: resources,
        });
        {
            // add to session
            let mut s = session.get_mut();
            s.tasks.insert(sref.clone());
            s.unfinished_tasks += 1;
        }
        {
            let s = sref.get_mut();
            // add to the DataObjects
            for i in s.inputs.iter() {
                let mut o = i.object.get_mut();
                o.consumers.insert(sref.clone());
                o.need_by.insert(sref.clone());
            }
            for out in s.outputs.iter() {
                let mut o = out.get_mut();
                o.producer = Some(sref.clone());
            }
        }
        Ok(sref)
    }
/// Create new Task with given inputs and outputs, connecting them together.
/// Checks the input and output object states and sessions.
Create new Task with given inputs and outputs, connecting them together.
Checks the input and output object states and sessions.
Create new Task with given inputs and outputs connecting them together . Checks the input and output object states and sessions .
pub fn new(
        session: &SessionRef,
        id: TaskId,
        inputs: Vec<TaskInput>,
        outputs: Vec<DataObjectRef>,
        task_type: String,
        attributes: Attributes,
        resources: Resources,
    ) -> Result<Self> {
        assert_eq!(id.get_session_id(), session.get_id());
        let mut waiting = RcSet::new();
        for i in inputs.iter() {
            let inobj = i.object.get();
            match inobj.state {
                DataObjectState::Removed => {
                    bail!(
                        "Can't create Task {} with Finished input object {}",
                        id,
                        inobj.id
                    );
                }
                DataObjectState::Finished => {}
                DataObjectState::Unfinished => {
                    waiting.insert(i.object.clone());
                }
            }
            if inobj.id.get_session_id() != id.get_session_id() {
                bail!(
                    "Input object {} for task {} is from a different session",
                    inobj.id,
                    id
                );
            }
        }
        for out in outputs.iter() {
            let o = out.get();
            if let Some(ref prod) = o.producer {
                bail!(
                    "Object {} already has producer (task {}) when creating task {}",
                    o.id,
                    prod.get().id,
                    id
                );
            }
            if o.id.get_session_id() != id.get_session_id() {
                bail!(
                    "Output object {} for task {} is from a different session",
                    o.id,
                    id
                );
            }
        }
        let sref = TaskRef::wrap(Task {
            id: id,
            state: if waiting.is_empty() {
                TaskState::Ready
            } else {
                TaskState::NotAssigned
            },
            inputs: inputs,
            outputs: outputs.into_iter().collect(),
            waiting_for: waiting,
            assigned: None,
            scheduled: None,
            session: session.clone(),
            task_type: task_type,
            finish_hooks: Default::default(),
            attributes: attributes,
            resources: resources,
        });
        {
            // add to session
            let mut s = session.get_mut();
            s.tasks.insert(sref.clone());
            s.unfinished_tasks += 1;
        }
        {
            let s = sref.get_mut();
            // add to the DataObjects
            for i in s.inputs.iter() {
                let mut o = i.object.get_mut();
                o.consumers.insert(sref.clone());
                o.need_by.insert(sref.clone());
            }
            for out in s.outputs.iter() {
                let mut o = out.get_mut();
                o.producer = Some(sref.clone());
            }
        }
        Ok(sref)
    }
pub fn new ( session : & SessionRef , id : TaskId , inputs : Vec < TaskInput > , outputs : Vec < DataObjectRef > , task_type : String , attributes : Attributes , resources : Resources , ) -> Result < Self > { assert_eq ! ( id get_session_id ( ) session get_id ( ) ) ; let mut waiting = RcSet :: new ( ) ; for i in inputs . iter ( ) { let inobj = i . object . get ( ) ; match inobj . state { DataObjectState :: Removed => { bail ! ( " " id inobj id ) ; } DataObjectState :: Finished => { } DataObjectState :: Unfinished => { waiting . insert ( i . object . clone ( ) ) ; } } if inobj . id . get_session_id ( ) != id . get_session_id ( ) { bail ! ( " " inobj id id ) ; } } for out in outputs . iter ( ) { let o = out . get ( ) ; if let Some ( ref prod ) = o . producer { bail ! ( " " o id prod get ( ) id id ) ; } if o . id . get_session_id ( ) != id . get_session_id ( ) { bail ! ( " " o id id ) ; } } let sref = TaskRef :: wrap ( Task { id : id , state : if waiting . is_empty ( ) { TaskState :: Ready } else { TaskState :: NotAssigned } , inputs : inputs , outputs : outputs . into_iter ( ) . collect ( ) , waiting_for : waiting , assigned : None , scheduled : None , session : session . clone ( ) , task_type : task_type , finish_hooks : Default :: default ( ) , attributes : attributes , resources : resources , } ) ; { // add to session let mut s = session . get_mut ( ) ; s . tasks . insert ( sref . clone ( ) ) ; s . unfinished_tasks += 1 ; } { let s = sref . get_mut ( ) ; // add to the DataObjects for i in s . inputs . iter ( ) { let mut o = i . object . get_mut ( ) ; o . consumers . insert ( sref . clone ( ) ) ; o . need_by . insert ( sref . clone ( ) ) ; } for out in s . outputs . iter ( ) { let mut o = out . get_mut ( ) ; o . producer = Some ( sref . clone ( ) ) ; } } Ok ( sref ) }
Create new Task with given inputs and outputs, connecting them together.
Create new Task with given inputs and outputs connecting them together .
session
&SessionRef
id
TaskId
inputs
Vec<TaskInput>
outputs
Vec<DataObjectRef>
task_type
String
attributes
Attributes
resources
Resources
session
&SessionRef
id
TaskId
inputs
Vec<TaskInput>
outputs
Vec<DataObjectRef>
task_type
String
attributes
Attributes
resources
Resources