Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add soft time limit for Celery tasks #3019

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions refinery/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def get_setting(name, settings=local_settings, default=None):
CELERYD_MAX_TASKS_PER_CHILD = get_setting("CELERYD_MAX_TASKS_PER_CHILD")
CELERY_ROUTES = {"file_store.tasks.FileImportTask": {"queue": "file_import"}}
CELERY_ACCEPT_CONTENT = ['pickle']
CELERYD_TASK_SOFT_TIME_LIMIT = 60 # seconds
CELERYBEAT_SCHEDULE = {
'collect_site_statistics': {
'task': 'core.tasks.collect_site_statistics',
Expand Down
4 changes: 3 additions & 1 deletion refinery/file_store/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

class FileImportTask(celery.Task):

soft_time_limit = 3600 # 1 hour

def run(self, item_uuid):
"""Download or copy data file for FileStoreItem specified by UUID
Fail the task in case of errors (http://stackoverflow.com/a/33143545)
Expand Down Expand Up @@ -68,7 +70,7 @@ def run(self, item_uuid):
file_store_name = self.import_s3_to_path(item.source)
else:
file_store_name = self.import_url_to_path(item.source)
except RuntimeError as exc:
except (RuntimeError, celery.exceptions.SoftTimeLimitExceeded) as exc:
logger.error("File import failed: %s", exc)
self.update_state(state=celery.states.FAILURE,
meta='Failed to import file')
Expand Down