def rebuildIndex(collections): context = {'model': model, 'user': c.user} if not isAdmin(): raise Exception('Nope.') list = logic.get_action('package_list')(context,{}) # clear the current collection collections.get("package_search").remove({}) for pkgId in list: context = {'model': model, 'user': c.user} ckanPackage = logic.get_action('package_show')(context,{id: pkgId}) mapreducePackage(ckanPackage, collections.get("spectra_search"), collections.get("package_search")) return json.dumps({'success': True, 'rebuildCount': len(list)})
def sub_run(q, ckanPackage, emailOnComplete, emailAddress, username): try: # calculate bounding box from spectra (lat/lng was provided) total = query.total(ckanPackage.get('id')).get('total') bbox = { "maxlat" : -9999, "minlat" : 9999, "maxlng" : -9999, "minlng" : 9999, "use" : False } # grab each spectra and insert into public EcoSIS search for i in range(0, total): spectra = query.get(ckanPackage.get('id'), index=i, must_be_valid=True, clean_wavelengths=False) if not 'datapoints' in spectra: continue if len(spectra['datapoints']) == 0: continue # update search spectraCollection.insert(spectra) # update the bounding box if the spectra has a lat/lng updateBbox(spectra, bbox) # see if we found a bounding box from the spectra if bbox["maxlat"] != -9999 and bbox["maxlng"] != -9999 and bbox["minlng"] != 9999 and bbox["minlng"] != -9999: bbox["use"] = True # mapreduce the dataset package data mapreduce.mapreducePackage(ckanPackage, bbox) # alert (email user) or quit if not emailOnComplete: updateLookup() return try: send_notification( { "email" : emailAddress, "display_name" : username }, { "subject" : "EcoSIS Push Successful", "body" : ("Your dataset '%s' has been pushed to EcoSIS Search. " "You can view your dataset here: %s#result/%s" "\n\n-The EcoSIS Team") % (ckanPackage.get('title'), config.get('ecosis.search_url'), ckanPackage.get("id")) } ) except Exception as e: print "Failed to send email: %s" % emailAddress updateLookup() except Exception as e: try: print 'ERROR pushing to search: %s' % ckanPackage.get('id') # if badness, remove from search deleteUtils.cleanFromSearch(ckanPackage.get('id')) print e if not emailOnComplete: return send_notification( { "email" : emailAddress, "display_name" : username }, { "subject" : "EcoSIS Push Failed", "body" : ("Your recent push to search for '%s' has failed. " "You can try again or contact [email protected]. " "We apologize for the inconvenience\n\n-The EcoSIS Team") % (ckanPackage["title"]) } ) except: pass