Exemple #1
0
 def delete(self, id_webiste):
     try:
         return es.delete(index="website",
                          doc_type='website-type',
                          id=id_webiste)
     except ElasticsearchException as e:
         logger.exception(
             "WebsiteNoSql delete. website_id={0}.  Erro:{1}".format(
                 id_webiste, str(e)))  # noqa
         raise ElasticsearchException()
Exemple #2
0
 def create(self, id_webiste, body):
     try:
         es.index(index="website",
                  doc_type='website-type',
                  id=id_webiste,
                  body=body)
     except ElasticsearchException as e:
         logger.exception(
             "WebsiteNoSql create. website_id={0}, body={1}, Erro:{1}".
             format(id_webiste, str(body), str(e)))  # noqa
         raise ElasticsearchException()
Exemple #3
0
 def get(self, id_webiste):
     try:
         return es.get(index="website",
                       doc_type='website-type',
                       id=id_webiste)
     except NotFoundError as e:
         return None
     except ElasticsearchException as e:
         logger.exception(
             "WebsiteNoSql get. website_id={0}.  Erro:{1}".format(
                 id_webiste, str(e)))  # noqa
         raise ElasticsearchException()
Exemple #4
0
def process_available_links(self, website_id):

    logger.info(
        "Task to process available links: started. website_id={0}".format(
            website_id))  # noqa

    try:
        website = Website.query.filter(Website.id == website_id).first()

        if not website:
            logger.error(
                "Task to process available links: website not found. website_id={0}"
                .format(website_id))  # noqa
            raise TasksException(
                'Website not found: website_id={0}'.format(website_id))  # noqa

        WebsiteBackend().save_website_available_links(website)

    except ConnectTimeout as exc:
        self.retry(exc=exc, countdown=180)
    except SQLAlchemyError as exc:
        db.session.rollback()
        self.retry(exc=exc, countdown=180)
    except TasksException as e:
        raise TasksException(str(e))
    except Exception as e:
        logger.exception(
            "Task to process available links: exception. website_id={0}".
            format(website_id))  # noqa

        if website:
            WebsiteBackend().failed_save_website_available_links(
                website, str(e))  # noqa

    logger.info(
        "Task to process available links: ended. website_id={0}".format(
            website_id))  # noqa