fn download_structure(structure_id: LocationID,
                      mut client: esi::Client,
                      uni: universe::Universe)
                      -> thread::JoinHandle<Result<store::TaggedOrderVec>> {
    thread::spawn(move || {
        // Todo: Retry
        let metadata_result = client.get_orders_structure_metadata(structure_id);

        let metadata = match metadata_result {
            Ok(metadata) => metadata,
            Err(e) => {
                // If we got forbidden, blacklist structure and return empty list. On all other errors bail.
                if let errors::ErrorKind::HTTPForbiddenError(ref _e) = *e.kind() {
                    uni.blacklist_structure(structure_id);
                    debug!("Blacklisted structure {}.", structure_id);
                    // Return empty list
                    return Ok(Vec::new());
                }

                bail!(e);
            }
        };

        // Spawn threads for pages
        let mut page_handles: Vec<thread::JoinHandle<Result<Vec<Order>>>> = Vec::new();
        for page in 1..=metadata.pages {
            let handle = download_structure_page(structure_id, client.clone(), page);
            page_handles.push(handle);
        }

        let mut orders: store::TaggedOrderVec = Vec::new();
        for handle in page_handles {
            // Unpack thread panic
            let thread_result = handle.join().unwrap();

            // Unpack thread result
            let pages = thread_result?;

            for order in pages {
                orders.push((order, metadata.last_modified));
            }
        }

        Ok(orders)
    })
}
/// Download structure metadata and spawn page threads
Download structure metadata and spawn page threads
Download structure metadata and spawn page threads
fn download_structure(structure_id: LocationID,
                      mut client: esi::Client,
                      uni: universe::Universe)
                      -> thread::JoinHandle<Result<store::TaggedOrderVec>> {
    thread::spawn(move || {
        // Todo: Retry
        let metadata_result = client.get_orders_structure_metadata(structure_id);
        let metadata = match metadata_result {
            Ok(metadata) => metadata,
            Err(e) => {
                // If we got forbidden, blacklist structure and return empty list. On all other errors bail.
                if let errors::ErrorKind::HTTPForbiddenError(ref _e) = *e.kind() {
                    uni.blacklist_structure(structure_id);
                    debug!("Blacklisted structure {}.", structure_id);
                    // Return empty list
                    return Ok(Vec::new());
                }
                bail!(e);
            }
        };
        // Spawn threads for pages
        let mut page_handles: Vec<thread::JoinHandle<Result<Vec<Order>>>> = Vec::new();
        for page in 1..=metadata.pages {
            let handle = download_structure_page(structure_id, client.clone(), page);
            page_handles.push(handle);
        }
        let mut orders: store::TaggedOrderVec = Vec::new();
        for handle in page_handles {
            // Unpack thread panic
            let thread_result = handle.join().unwrap();
            // Unpack thread result
            let pages = thread_result?;
            for order in pages {
                orders.push((order, metadata.last_modified));
            }
        }
        Ok(orders)
    })
}
fn download_structure ( structure_id : LocationID , mut client : esi :: Client , uni : universe :: Universe ) -> thread :: JoinHandle < Result < store :: TaggedOrderVec > > { thread :: spawn ( move | | { // Todo: Retry let metadata_result = client . get_orders_structure_metadata ( structure_id ) ; let metadata = match metadata_result { Ok ( metadata ) => metadata , Err ( e ) => { // If we got forbidden, blacklist structure and return empty list. On all other errors bail. if let errors :: ErrorKind :: HTTPForbiddenError ( ref _e ) = * e . kind ( ) { uni . blacklist_structure ( structure_id ) ; debug ! ( " " structure_id ) ; // Return empty list return Ok ( Vec :: new ( ) ) ; } bail ! ( e ) ; } } ; // Spawn threads for pages let mut page_handles : Vec < thread :: JoinHandle < Result < Vec < Order > > > > = Vec :: new ( ) ; for page in 1 ..= metadata . pages { let handle = download_structure_page ( structure_id , client . clone ( ) , page ) ; page_handles . push ( handle ) ; } let mut orders : store :: TaggedOrderVec = Vec :: new ( ) ; for handle in page_handles { // Unpack thread panic let thread_result = handle . join ( ) . unwrap ( ) ; // Unpack thread result let pages = thread_result ? ; for order in pages { orders . push ( ( order , metadata . last_modified ) ) ; } } Ok ( orders ) } ) }
Download structure metadata and spawn page threads
Download structure metadata and spawn page threads
structure_id
LocationID
client
esi::Client
uni
universe::Universe
structure_id
LocationID
client
esi::Client
uni
universe::Universe