Skip to content

Commit 77aa658

Browse files
authored
[ENH] add cluster table metadata (#1045)
* oops mixed changes * keep track of filename with cluster table * reference correct code * run black * fix flake8 errors * refactor celery to work with app * remove the unix socket
1 parent 6197f61 commit 77aa658

File tree

15 files changed

+221
-262
lines changed

15 files changed

+221
-262
lines changed

compose/backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ RUN pip install --no-cache-dir .[dev]
3333
# Now copy the rest of the app
3434
COPY . /compose/backend/
3535

36-
RUN pip install --no-cache-dir .
36+
RUN pip install --no-cache-dir -e .
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from celery import Celery
2+
3+
4+
def make_celery(app):
5+
celery = Celery(
6+
app.import_name,
7+
backend=app.config.get("CELERY_RESULT_BACKEND"),
8+
broker=app.config.get("CELERY_BROKER_URL"),
9+
)
10+
celery.conf.update(app.config)
11+
TaskBase = celery.Task
12+
13+
class ContextTask(TaskBase):
14+
def __call__(self, *args, **kwargs):
15+
with app.app_context():
16+
return TaskBase.__call__(self, *args, **kwargs)
17+
18+
celery.Task = ContextTask
19+
return celery
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from flask_celeryext import FlaskCeleryExt
2-
31
from .__init__ import create_app
2+
from .celery_app import make_celery
43

54
app = create_app()
6-
7-
ext_celery = FlaskCeleryExt(app)
8-
celery_app = ext_celery.celery
5+
celery_app = make_celery(app)

compose/backend/neurosynth_compose/models/analysis.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ class Project(BaseMixin, db.Model):
230230
name = db.Column(db.Text)
231231
description = db.Column(db.Text)
232232
provenance = db.Column(db.JSON)
233-
user_id = db.Column(
234-
db.Text, db.ForeignKey("users.external_id"), index=True
235-
)
233+
user_id = db.Column(db.Text, db.ForeignKey("users.external_id"), index=True)
236234
public = db.Column(db.Boolean, default=True, index=True)
237235
draft = db.Column(db.Boolean, default=True, index=True)
238236

compose/backend/neurosynth_compose/resources/analysis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
NeurostoreStudySchema,
4949
ProjectSchema,
5050
)
51+
from ..tasks.neurostore import create_or_update_neurostore_analysis
52+
from ..tasks.neurovault import file_upload_neurovault
53+
from celery import group
54+
5155
from .singular import singularize
5256

5357

@@ -521,9 +525,6 @@ def post(self):
521525
return self.__class__._schema().dump(record)
522526

523527
def put(self, id):
524-
from .tasks import file_upload_neurovault, create_or_update_neurostore_analysis
525-
from celery import group
526-
527528
result = self._model.query.filter_by(id=id).one()
528529

529530
if request.files:

compose/backend/neurosynth_compose/resources/tasks.py

Lines changed: 0 additions & 176 deletions
This file was deleted.
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
"""Celery tasks package."""
22

3-
from .neurovault import file_upload_neurovault
4-
from .neurostore import create_or_update_neurostore_analysis
5-
from ..core import celery_app
6-
7-
__all__ = [
8-
"file_upload_neurovault",
9-
"create_or_update_neurostore_analysis",
10-
]
11-
12-
# Register tasks
13-
celery_app.tasks.register(file_upload_neurovault)
14-
celery_app.tasks.register(create_or_update_neurostore_analysis)
3+
# Celery tasks are now registered via decorators or autodiscovery.

compose/backend/neurosynth_compose/tasks/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ def __call__(self, *args, **kwargs):
2727
result = self._orig_run(*args, **kwargs)
2828
bound_logger.info("task_completed", extra={"task_name": self.name})
2929
return result
30-
except Exception as exc:
31-
bound_logger.exception(
32-
"task_failed", extra={"task_name": self.name, "exc_info": exc}
33-
)
30+
except Exception:
31+
bound_logger.exception("task_failed", extra={"task_name": self.name})
3432
raise
3533

3634
def on_failure(self, exc, task_id, args, kwargs, einfo):

0 commit comments

Comments
 (0)