Пример #1
0
    def run(self, ckanPackage, emailOnComplete=False, emailAddress="", username=""):
        # first clean out data
        deleteUtils.cleanFromSearch(ckanPackage.get('id'))

        # we don't want to push private datasets to public search
        if ckanPackage.get('private') == True:
            raise Exception('This dataset is private')

        # set the citation field
        setCitation(ckanPackage)
        context = {'model': model, 'user': c.user}
        ckanPackage = logic.get_action('package_update')(context, ckanPackage)

        # start our new thread
        q = Queue()
        p = Process(target=sub_run, args=(q, ckanPackage, emailOnComplete, emailAddress, username))
        p.start()

        return {'success': True, 'emailing': emailOnComplete, 'email': emailAddress}
Пример #2
0
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