/// main worker loop for a single thread, works in perpetuity or up to a specified `limit`
main worker loop for a single thread, works in perpetuity or up to a specified `limit`
main worker loop for a single thread works in perpetuity or up to a specified ` limit `
fn start_single(&self, limit: Option<usize>) -> Result<(), Box<dyn Error>> {
    let mut work_counter = 0;
    // Connect to a task ventilator
    let context_source = Context::new();
    let source = context_source.socket(zmq::DEALER).unwrap();
    source.set_identity(self.get_identity().as_bytes()).unwrap();
    assert!(source.connect(&self.get_source_address()).is_ok());
    // Connect to a task sink
    let context_sink = Context::new();
    let sink = context_sink.socket(zmq::PUSH).unwrap();
    assert!(sink.connect(&self.get_sink_address()).is_ok());
    // Work in perpetuity
    loop {
      // Prepare a File for the input
      let input_tmpdir = TempDir::new("cortex_task").unwrap();
      let (file_result, input_filepath, input_size, taskid) =
        self.receive_from_cortex(&input_tmpdir, &source);
      let converted_result = if file_result.is_ok() {
        self.convert(Path::new(&input_filepath))
      } else {
        file_result
      };
      self.respond_to_cortex(converted_result, input_size, &taskid, &sink);
      input_tmpdir.close().unwrap();
      work_counter += 1;
      if let Some(upper_bound) = limit {
        if work_counter >= upper_bound {
          // Give enough time to complete the Final job.
          thread::sleep(Duration::new(1, 0));
          break;
        }
      }
    }
    Ok(())
  }
fn start_single ( & self , limit : Option < usize > ) -> Result < ( ) , Box < dyn Error > > { let mut work_counter = 0 ; // Connect to a task ventilator let context_source = Context :: new ( ) ; let source = context_source . socket ( zmq :: DEALER ) . unwrap ( ) ; source . set_identity ( self . get_identity ( ) . as_bytes ( ) ) . unwrap ( ) ; assert ! ( source connect ( self get_source_address ( ) ) is_ok ( ) ) ; // Connect to a task sink let context_sink = Context :: new ( ) ; let sink = context_sink . socket ( zmq :: PUSH ) . unwrap ( ) ; assert ! ( sink connect ( self get_sink_address ( ) ) is_ok ( ) ) ; // Work in perpetuity loop { // Prepare a File for the input let input_tmpdir = TempDir :: new ( " " ) . unwrap ( ) ; let ( file_result , input_filepath , input_size , taskid ) = self . receive_from_cortex ( & input_tmpdir , & source ) ; let converted_result = if file_result . is_ok ( ) { self . convert ( Path :: new ( & input_filepath ) ) } else { file_result } ; self . respond_to_cortex ( converted_result , input_size , & taskid , & sink ) ; input_tmpdir . close ( ) . unwrap ( ) ; work_counter += 1 ; if let Some ( upper_bound ) = limit { if work_counter >= upper_bound { // Give enough time to complete the Final job. thread :: sleep ( Duration :: new ( 1 , 0 ) ) ; break ; } } } Ok ( ( ) ) }
main worker loop for a single thread, works in perpetuity or up to a specified `limit`
main worker loop for a single thread works in perpetuity or up to a specified ` limit `
&self
limit
Option<usize>