Skip to content

Commit

Permalink
refactor(worker): Drop gevent from asgi worker
Browse files Browse the repository at this point in the history
  • Loading branch information
nellh committed Aug 5, 2024
1 parent 067b774 commit ac475e1
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 194 deletions.
1 change: 0 additions & 1 deletion services/datalad/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ requests = "*"
GitPython = "*"
PyJWT = ">=2"
gunicorn = "*"
gevent = "*"
elastic-apm = "*"
falcon-elastic-apm = "*"
boto3 = "*"
Expand Down
278 changes: 96 additions & 182 deletions services/datalad/Pipfile.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions services/datalad/datalad_service/handlers/publish.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio

import falcon
import gevent

from datalad_service.tasks.publish import create_remotes_and_export

Expand All @@ -13,7 +14,7 @@ def __init__(self, store):

async def on_post(self, req, resp, dataset):
dataset_path = self.store.get_dataset_path(dataset)
gevent.spawn(create_remotes_and_export,
dataset_path, cookies=req.cookies)
asyncio.get_event_loop().run_in_executor(None, create_remotes_and_export,

Check warning on line 17 in services/datalad/datalad_service/handlers/publish.py

View check run for this annotation

Codecov / codecov/patch

services/datalad/datalad_service/handlers/publish.py#L17

Added line #L17 was not covered by tests
dataset_path, cookies=req.cookies)
resp.media = {}
resp.status = falcon.HTTP_OK
6 changes: 4 additions & 2 deletions services/datalad/datalad_service/handlers/reexporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio

import falcon
import logging
import gevent

from datalad_service.tasks.publish import export_dataset

Expand All @@ -12,5 +13,6 @@ def __init__(self, store):

async def on_post(self, req, resp, dataset):
dataset_path = self.store.get_dataset_path(dataset)
gevent.spawn(export_dataset, dataset_path, req.cookies)
asyncio.get_event_loop().run_in_executor(None, export_dataset,

Check warning on line 16 in services/datalad/datalad_service/handlers/reexporter.py

View check run for this annotation

Codecov / codecov/patch

services/datalad/datalad_service/handlers/reexporter.py#L16

Added line #L16 was not covered by tests
dataset_path, cookies=req.cookies)
resp.status = falcon.HTTP_OK
10 changes: 6 additions & 4 deletions services/datalad/datalad_service/handlers/remote_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import falcon

import asyncio
import logging
import gevent

import falcon

from datalad_service.tasks.remote_import import remote_import
from datalad_service.common.user import get_user_info
Expand All @@ -16,6 +18,6 @@ async def on_post(self, req, resp, dataset, import_id):
dataset_path = self.store.get_dataset_path(dataset)
upload_path = self.store.get_upload_path(dataset, import_id)
url = (await req.get_media())['url']
gevent.spawn(remote_import, dataset_path,
upload_path, import_id, url, name, email, req.cookies)
asyncio.get_event_loop().run_in_executor(None, remote_import, dataset_path,

Check warning on line 21 in services/datalad/datalad_service/handlers/remote_import.py

View check run for this annotation

Codecov / codecov/patch

services/datalad/datalad_service/handlers/remote_import.py#L20-L21

Added lines #L20 - L21 were not covered by tests
upload_path, import_id, url, name, email, req.cookies)
resp.status = falcon.HTTP_OK
5 changes: 3 additions & 2 deletions services/datalad/datalad_service/handlers/snapshots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import os
import logging

import gevent
import falcon

from datalad_service.tasks.snapshots import SnapshotDescriptionException, create_snapshot, get_snapshot, get_snapshots, SnapshotExistsException
Expand Down Expand Up @@ -60,7 +60,8 @@ async def on_post(self, req, resp, dataset, snapshot):
if not skip_publishing:
monitor_remote_configs(ds_path)
# Publish after response
gevent.spawn(export_dataset, ds_path, req.cookies)
asyncio.get_event_loop().run_in_executor(None, export_dataset,
ds_path, req.cookies)
except SnapshotExistsException as err:
resp.media = {'error': repr(err)}
resp.status = falcon.HTTP_CONFLICT
Expand Down

0 comments on commit ac475e1

Please sign in to comment.