From dacec47340fe43de33483862266de3d2b993a92c Mon Sep 17 00:00:00 2001 From: iamareebjamal Date: Tue, 21 May 2019 21:59:17 +0530 Subject: [PATCH 1/2] chore: Change requirements syntax --- requirements/common.txt | 102 ++++++++++++++++++++-------------------- requirements/dev.txt | 7 +-- requirements/tests.txt | 4 +- 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/requirements/common.txt b/requirements/common.txt index cd202c902e..dc9e93be10 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -1,59 +1,59 @@ pycparser==2.14 # Only 2.14 works. -Flask>=1.0,<1.1 -Flask-Script>=2.0.5,<2.1 -Flask-SQLAlchemy>=2.1,<2.2 -Flask-Migrate>=2.0.0,<3 -Flask-Login>=0.4,<1 -Flask-Scrypt>=0.1.3.6,<0.2 -Flask-JWT>=0.3.2,<0.4 -requests-oauthlib>=0.7.0,<1 -icalendar>=3.11,<4 -requests[security]>=2.20.0,<3 -psycopg2-binary -SQLAlchemy-Utils>=0.32.12,<0.33 -itsdangerous>=0.24,<0.30 -humanize>=0.5.1,<0.6 -celery>=3.1.23,<4 -redis>=2.10.5,<4 -apscheduler>=3.3.0,<4 -pillow -sendgrid>=6.0.5 -amqp<2.0,>=1.4.9 -gunicorn>=19.6.0,<20 -boto>=2.45.0,<3 -geoip2>=2.4.2,<3 -SQLAlchemy-Continuum>=1.2.4,<2 -arrow>=0.10.0,<1 -unicode-slugify>=0.1.3,<1 -bleach>=2.1.3 -stripe>=1.44.0,<3 -xhtml2pdf -flask-caching>=1.4.0,<1.5 -forex-python>=0.3.1,<2 -oauth2>=1.9.0.post1,<2 -qrcode>=5.3,<6 -python-magic>=0.4.12,<1 -python-geoip>=1.2,<2 -marrow.mailer>=4.0.2,<5 -flask-cors>=3.0.2,<3.1 +Flask~=1.0.3 +Flask-Script~=2.0.6 +Flask-SQLAlchemy~=2.1 +Flask-Migrate~=2.5 +Flask-Login~=0.4 +Flask-Scrypt~=0.1.3 +Flask-JWT~=0.3.2 +requests-oauthlib~=0.8 +icalendar~=3.12 +requests[security]~=2.20 +psycopg2-binary~=2.8.2 +SQLAlchemy-Utils~=0.32.21 +itsdangerous~=0.24 +humanize~=0.5.1 +celery~=3.1.26 +redis~=3.2 +apscheduler~=3.6.0 +pillow~=6.0.0 +amqp~=1.4.9 +gunicorn~=19.9 +boto>=2.49 +geoip2>=2.9 +SQLAlchemy-Continuum>=1.3 +arrow>=0.13 +unicode-slugify~=0.1 +bleach~=3.1 +stripe~=2.28 +xhtml2pdf~=0.2 +flask-caching~=1.4 +forex-python~=1.5 +oauth2~=1.9 +qrcode~=5.3 +python-magic~=0.4 +python-geoip~=1.2 +marrow.mailer~=4.0 +flask-cors~=3.0.7 python-pentabarf-xml==0.19 # leave versions untouched. python-geoip-geolite2 pycountry pytz diff-match-patch -blinker -envparse +blinker~=1.4 +envparse~=0.2 -e git+https://github.com/fossasia/flask-rest-jsonapi.git@shubhamp-master#egg=flask-rest-jsonapi -wtforms -flask-admin -google-compute-engine -factory_boy -raven[flask] -healthcheck -elasticsearch-dsl -flask-redis -SQLAlchemy>=1.3.0<2.0.0 -Flask-Elasticsearch -paypalrestsdk -eventlet +wtforms~=2.2 +flask-admin~=1.5 +google-compute-engine~=2.8 +factory_boy~=2.12 +raven[flask]~=6.10 +healthcheck~=1.3 +elasticsearch-dsl~=7.0 +flask-redis~=0.3 +SQLAlchemy~=1.3.3 +Flask-Elasticsearch~=0.2 +paypalrestsdk~=1.13 +eventlet~=0.24 pyyaml~=5.1 +sendgrid~=6.0 diff --git a/requirements/dev.txt b/requirements/dev.txt index d3b81e393a..6fcc32cf0b 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,4 +1,5 @@ -r common.txt -nose>=1.3.7,<2 -pylint>=1.6.4,<3 -pep8>=1.7.0,<2 + +nose~=1.3 +pylint~=2.3 +pep8~=1.7 diff --git a/requirements/tests.txt b/requirements/tests.txt index d3f1a09a85..cd9b643931 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,4 +1,4 @@ -r dev.txt -coverage>=4.2,<5 -dredd_hooks==0.2.0 +coverage~=4.5 +dredd_hooks~=0.2 From 405966a80346979d401259ae5af9dfa3ebcd2f2f Mon Sep 17 00:00:00 2001 From: iamareebjamal Date: Tue, 21 May 2019 23:38:01 +0530 Subject: [PATCH 2/2] fix: Celery tasks with new version --- app/__init__.py | 21 +++++---------------- app/api/helpers/tasks.py | 2 +- requirements/common.txt | 5 +++-- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 7e3b1be5ea..f70e225f5e 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -4,6 +4,7 @@ from envparse import env import sys from flask import Flask, json, make_response +from flask_celeryext import FlaskCeleryExt from app.settings import get_settings, get_setts from flask_migrate import Migrate, MigrateCommand from flask_script import Manager @@ -187,20 +188,8 @@ def track_user(): def make_celery(app=None): app = app or create_app()[0] celery.conf.update(app.config) - task_base = celery.Task - - class ContextTask(task_base): - abstract = True - - def __call__(self, *args, **kwargs): - if current_app.config['TESTING']: - with app.test_request_context(): - return task_base.__call__(self, *args, **kwargs) - with app.app_context(): - return task_base.__call__(self, *args, **kwargs) - - celery.Task = ContextTask - return celery + ext = FlaskCeleryExt(app) + return ext.celery # Health-check @@ -215,13 +204,13 @@ def __call__(self, *args, **kwargs): # http://stackoverflow.com/questions/9824172/find-out-whether-celery-task-exists @after_task_publish.connect -def update_sent_state(sender=None, body=None, **kwargs): +def update_sent_state(sender=None, headers=None, **kwargs): # the task may not exist if sent using `send_task` which # sends tasks by name, so fall back to the default result backend # if that is the case. task = celery.tasks.get(sender) backend = task.backend if task else celery.backend - backend.store_result(body['id'], None, 'WAITING') + backend.store_result(headers['id'], None, 'WAITING') # register celery tasks. removing them will cause the tasks to not function. so don't remove them diff --git a/app/api/helpers/tasks.py b/app/api/helpers/tasks.py index 002a581dad..8f09a0d5fa 100644 --- a/app/api/helpers/tasks.py +++ b/app/api/helpers/tasks.py @@ -5,6 +5,7 @@ import uuid from flask import current_app, render_template +from flask_celeryext import RequestContextTask from marrow.mailer import Mailer, Message from app import get_settings from sendgrid import SendGridAPIClient @@ -25,7 +26,6 @@ import traceback from app.api.helpers.files import create_save_image_sizes, create_save_resized_image -from app.api.helpers.request_context_task import RequestContextTask from app.api.helpers.mail import send_export_mail, send_import_mail from app.api.helpers.notification import send_notif_after_import, send_notif_after_export from app.api.helpers.db import safe_query diff --git a/requirements/common.txt b/requirements/common.txt index dc9e93be10..de6404890c 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -6,6 +6,7 @@ Flask-Migrate~=2.5 Flask-Login~=0.4 Flask-Scrypt~=0.1.3 Flask-JWT~=0.3.2 +flask-celeryext~=0.3 requests-oauthlib~=0.8 icalendar~=3.12 requests[security]~=2.20 @@ -13,11 +14,11 @@ psycopg2-binary~=2.8.2 SQLAlchemy-Utils~=0.32.21 itsdangerous~=0.24 humanize~=0.5.1 -celery~=3.1.26 +celery~=4.3 redis~=3.2 apscheduler~=3.6.0 pillow~=6.0.0 -amqp~=1.4.9 +amqp~=2.4 gunicorn~=19.9 boto>=2.49 geoip2>=2.9