Пример #1
0
 def _action_store(self, conn, store_action):
     obj = store_action.get("store")
     if "index" not in obj:
         raise StoreException("no index provided for store action")
     if "record" not in obj:
         raise StoreException("no record provided for store action")
     raw.store(conn, obj.get("index"), obj.get("record"), obj.get("id"))
Пример #2
0
 def _action_store(self, conn, store_action):
     obj = store_action.get("store")
     if "index" not in obj:
         raise StoreException("no index provided for store action")
     if "record" not in obj:
         raise StoreException("no record provided for store action")
     raw.store(conn, obj.get("index"), obj.get("record"), obj.get("id"))
Пример #3
0
    def save(self, conn=None, makeid=True, created=True, updated=True, blocking=False, type=None):
        if conn is None:
            conn = self.__conn__

        type = self.get_write_type(type)

        if blocking and not updated:
            raise StoreException("Unable to do blocking save on record where last_updated is not set")

        now = util.now()
        if blocking:
            # we need the new last_updated time to be later than the new one
            if now == self.last_updated:
                time.sleep(1)   # timestamp granularity is seconds, so just sleep for 1
            now = util.now()    # update the new timestamp

        # the main body of the save
        if makeid:
            if "id" not in self.data:
                self.id = self.makeid()
        if created:
            if 'created_date' not in self.data:
                self.data['created_date'] = now
        if updated:
            self.data['last_updated'] = now

        raw.store(conn, type, self.data, self.id)

        if blocking:
            q = {
                "query" : {
                    "term" : {"id.exact" : self.id}
                },
                "fields" : ["last_updated"]
            }
            while True:
                res = raw.search(conn, type, q)
                j = raw.unpack_result(res)
                if len(j) == 0:
                    time.sleep(0.5)
                    continue
                if len(j) > 1:
                    raise StoreException("More than one record with id {x}".format(x=self.id))
                if j[0].get("last_updated")[0] == now:  # NOTE: only works on ES > 1.x
                    break
                else:
                    time.sleep(0.5)
                    continue
Пример #4
0
    def save(self,
             conn=None,
             makeid=True,
             created=True,
             updated=True,
             blocking=False,
             type=None,
             max_wait=False):
        if conn is None:
            conn = self._get_connection()

        if type is None:
            type = self._get_write_type()

        if blocking and not updated:
            raise StoreException(
                "Unable to do blocking save on record where last_updated is not set"
            )

        now = util.now()
        if blocking:
            # we need the new last_updated time to be later than the new one
            if now == self.last_updated:
                time.sleep(
                    1)  # timestamp granularity is seconds, so just sleep for 1
            now = util.now()  # update the new timestamp

        # the main body of the save
        if makeid:
            if "id" not in self.data:
                self.id = self.makeid()
        if created:
            if 'created_date' not in self.data:
                self.data['created_date'] = now
        if updated:
            self.data['last_updated'] = now

        resp = raw.store(conn, type, self.data, self.id)
        if resp.status_code < 200 or resp.status_code >= 400:
            raise raw.ESWireException(resp)

        if blocking:
            if versions.fields_query(self._es_version):
                self._es_field_block(conn, type, now, max_wait)
            else:
                self._es_source_block(conn, type, now, max_wait)
Пример #5
0
    def save(self, conn=None, makeid=True, created=True, updated=True, blocking=False, type=None, max_wait=False):
        if conn is None:
            conn = self._get_connection()

        if type is None:
            type = self._get_write_type()

        if blocking and not updated:
            raise StoreException("Unable to do blocking save on record where last_updated is not set")

        now = util.now()
        if blocking:
            # we need the new last_updated time to be later than the new one
            if now == self.last_updated:
                time.sleep(1)   # timestamp granularity is seconds, so just sleep for 1
            now = util.now()    # update the new timestamp

        # the main body of the save
        if makeid:
            if "id" not in self.data:
                self.id = self.makeid()
        if created:
            if 'created_date' not in self.data:
                self.data['created_date'] = now
        if updated:
            self.data['last_updated'] = now

        resp = raw.store(conn, type, self.data, self.id)
        if resp.status_code < 200 or resp.status_code >= 400:
            raise raw.ESWireException(resp)

        if blocking:
            if versions.fields_query(self._es_version):
                self._es_field_block(conn, type, now, max_wait)
            else:
                self._es_source_block(conn, type, now, max_wait)
Пример #6
0
    def save(self,
             conn=None,
             makeid=True,
             created=True,
             updated=True,
             blocking=False,
             type=None):
        if conn is None:
            conn = self._get_connection()

        if type is None:
            type = self._get_write_type()

        if blocking and not updated:
            raise StoreException(
                "Unable to do blocking save on record where last_updated is not set"
            )

        now = util.now()
        if blocking:
            # we need the new last_updated time to be later than the new one
            if now == self.last_updated:
                time.sleep(
                    1)  # timestamp granularity is seconds, so just sleep for 1
            now = util.now()  # update the new timestamp

        # the main body of the save
        if makeid:
            if "id" not in self.data:
                self.id = self.makeid()
        if created:
            if 'created_date' not in self.data:
                self.data['created_date'] = now
        if updated:
            self.data['last_updated'] = now

        raw.store(conn, type, self.data, self.id)

        if blocking:
            q = {
                "query": {
                    "term": {
                        "id.exact": self.id
                    }
                },
                "fields": ["last_updated"]
            }
            while True:
                res = raw.search(conn, type, q)
                j = raw.unpack_result(res)
                if len(j) == 0:
                    time.sleep(0.5)
                    continue
                if len(j) > 1:
                    raise StoreException(
                        "More than one record with id {x}".format(x=self.id))
                if j[0].get("last_updated"
                            )[0] == now:  # NOTE: only works on ES > 1.x
                    break
                else:
                    time.sleep(0.5)
                    continue