From 6e682309d46b3bf939ec3ee4f668836dec0ccae8 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Fri, 28 May 2021 14:07:26 +0200 Subject: [PATCH] Now with Thread magic --- nest_backend/routes.py | 0 nest_backend/routes/repository/repositories.py | 11 ++++++++++- nest_crawler/repo_search.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 nest_backend/routes.py diff --git a/nest_backend/routes.py b/nest_backend/routes.py new file mode 100644 index 0000000..e69de29 diff --git a/nest_backend/routes/repository/repositories.py b/nest_backend/routes/repository/repositories.py index 2716d33..ac664bb 100644 --- a/nest_backend/routes/repository/repositories.py +++ b/nest_backend/routes/repository/repositories.py @@ -5,8 +5,16 @@ from nest_backend.gestione import * import datetime from flask_cors import cross_origin from nest_backend.errors import * +import nest_backend.app from nest_crawler.repo_search import search_repo_conditions +import threading + + +def tweet_importer(rid): + with nest_backend.app.app.app_context(): + search_repo_conditions(rid) + @cross_origin() @jwt_required() @@ -107,7 +115,8 @@ def page_repositories(): repository.start = datetime.datetime.now() ext.session.commit() try: - search_repo_conditions(repository.id) + thread = threading.Thread(target=tweet_importer, args=(repository.id,)) + thread.start() except Exception: return json_success(repository.to_json()), 201 return json_success(repository.to_json()), 201 diff --git a/nest_crawler/repo_search.py b/nest_crawler/repo_search.py index 30f7bc5..5cc0dee 100644 --- a/nest_crawler/repo_search.py +++ b/nest_crawler/repo_search.py @@ -4,6 +4,7 @@ from datetime import datetime, timedelta import tweepy as tw from nest_crawler.associate_condition_tweet import associate_condition_tweet + def search_repo_conditions(repository_id): api = authentication.authenticate()