Skip to content

Commit

Permalink
[FIX] celery context (#445)
Browse files Browse the repository at this point in the history
* try to remove multiple app contexts

* attempt #2 to fix

* update/fix task

* use actual celery app for task
  • Loading branch information
jdkent authored May 18, 2023
1 parent ecb4aa9 commit c41e929
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions compose/neurosynth_compose/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from flask_celeryext import FlaskCeleryExt

from .__init__ import create_app

app = create_app()

ext_celery = FlaskCeleryExt(app)
celery_app = ext_celery.celery
1 change: 1 addition & 0 deletions compose/neurosynth_compose/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ connexion[swagger-ui]~=2.13
email-validator~=1.1
flake8~=3.8
flask~=2.0
Flask-CeleryExt~=0.5
flask-cors~=3.0
flask-dance~=3.2
flask-shell-ipython~=0.4
Expand Down
10 changes: 3 additions & 7 deletions compose/neurosynth_compose/resources/tasks.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import os
from pathlib import Path

from celery import Celery
from flask import current_app as app

from ..__init__ import create_app
from ..core import celery_app
from ..database import db
from ..models import NeurovaultFile

app = create_app()
celery_app = Celery(app.import_name)
app.app_context().push()


@celery_app.task(name="neurovault.upload", bind=True)
def file_upload_neurovault(self, fpath, id):
Expand Down Expand Up @@ -40,7 +36,7 @@ def file_upload_neurovault(self, fpath, id):
record.collection_id,
fpath,
# https://github.com/NeuroVault/NeuroVault/blob/e3dc3c7767af12a3a7574eda64dcc9b749da8728/neurovault/apps/statmaps/models.py#LL1409C5-L1421C6
modality="Other", # no good way to determine if all inputs were of the same modality
modality="Other", # no good way to determine if all inputs were the same modality
# models.CharField(choices=
# [
# ('T', 'T map'),
Expand Down

0 comments on commit c41e929

Please sign in to comment.