Exemplo n.º 1
0
def _initiate_subbasin_mapshed_job_chain(mapshed_input, job_id):
    errback = save_job_error.s(job_id)

    area_of_interest, wkaoi = _parse_input(mapshed_input)

    if not wkaoi:
        raise ValidationError('You must provide the `wkaoi` key: ' +
                              'a HUC id is currently required for ' +
                              'subbasin modeling.')

    [layer_code, shape_id] = wkaoi.split('__')
    if layer_code not in ['huc8', 'huc10']:
        raise ValidationError('Only HUC-08s and HUC-10s are valid for ' +
                              'subbasin modeling.')

    huc12s = split_into_huc12s(layer_code, shape_id)
    if not huc12s:
        raise EmptyResultSet('No subbasins found')

    huc12_job_chains = []
    for (huc12_id, huc12, huc12_aoi) in huc12s:
        huc12_wkaoi = 'huc12__{id}'.format(id=huc12_id)
        huc12_job_chains.append(
            chain(
                (group(geoprocessing_chains(huc12_aoi, huc12_wkaoi, errback))
                 | collect_data.s(huc12_aoi, huc12).set(link_error=errback))))

    return chain(
        group(huc12_job_chains) | tasks.subbasin_results_to_dict.s()
        | save_job_result.s(job_id, mapshed_input)).apply_async()
Exemplo n.º 2
0
def _initiate_subbasin_mapshed_job_chain(mapshed_input, job_id):
    errback = save_job_error.s(job_id)

    area_of_interest, wkaoi = _parse_input(mapshed_input)

    if not wkaoi:
        raise ValidationError('You must provide the `wkaoi` key: ' +
                              'a HUC id is currently required for ' +
                              'subbasin modeling.')

    [layer_code, shape_id] = wkaoi.split('__')
    if layer_code not in ['huc8', 'huc10']:
        raise ValidationError('Only HUC-08s and HUC-10s are valid for ' +
                              'subbasin modeling.')

    huc12s = split_into_huc12s(layer_code, shape_id)
    if not huc12s:
        raise EmptyResultSet('No subbasins found')

    job_chain = (multi_subbasin(area_of_interest, huc12s)
                 | collect_subbasin.s(huc12s)
                 | tasks.subbasin_results_to_dict.s()
                 | save_job_result.s(job_id, mapshed_input))

    return job_chain.apply_async(link_error=errback)
Exemplo n.º 3
0
 def test_catch_empty_result_set(self, mock_generate_key,
                                 mock_cache_backend,
                                 invalidate_model_cache):
     """
     When an EmptyResultSet exception is raised in the process
     of passing an empty iterable to an __in parameter, CacheManager
     should correctly handle it and return None.
     """
     mock_generate_key.side_effect = EmptyResultSet()
     manufacturers = Manufacturer.objects.filter(name__in=[])
     self.assertEqual([], list(manufacturers))