Commit 9a4a481a authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

Added 'SUBMITTED' state to separate running from deleted tasks

parent 018548e8
Pipeline #2340 failed with stage
in 11 minutes and 50 seconds
......@@ -3,7 +3,8 @@ Celery instance."""
import logging
from celery import Celery
from celery import Celery, current_app
from celery.signals import after_task_publish
from flask import Flask
from fractalis.analytics.task import AnalyticTask
......@@ -14,6 +15,18 @@ from fractalis.utils import list_classes_with_base_class
logger = logging.getLogger(__name__)
# https://stackoverflow.com/questions/9824172/find-out-whether-celery-task-exists
@after_task_publish.connect
def update_submitted_state(sender=None, **kwargs):
"""Add 'SUBMITTED' state to celery task."""
# 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 = current_app.tasks.get(sender)
backend = task.backend if task else current_app.backend
backend.store_result(kwargs['headers']['id'], None, "SUBMITTED")
def make_celery(app: Flask) -> Celery:
"""Create a celery instance which executes its tasks in the application
context of our service.
......
......@@ -175,7 +175,7 @@ class TestAnalytics:
assert new_response.status_code == 200
new_body = flask.json.loads(new_response.get_data())
assert not new_body['result']
assert new_body['state'] == 'PENDING'
assert new_body['state'] == 'SUBMITTED'
def test_correct_response_if_task_fails(self, test_client):
rv = test_client.post('/analytics', data=flask.json.dumps(dict(
......
......@@ -231,7 +231,7 @@ class TestData:
for data_state in body['data_states']:
assert 'file_path' not in data_state
assert 'meta' not in data_state
assert data_state['etl_state'] == 'PENDING'
assert data_state['etl_state'] == 'SUBMITTED'
assert not data_state['etl_message']
assert data_state['data_type'] == 'mock'
assert not data_state['loaded']
......
"""This module provides tests for the session interface of Fractalis."""
from uuid import UUID
from time import sleep
......@@ -8,7 +9,7 @@ from redis import StrictRedis
# noinspection PyMissingOrEmptyDocstring,PyMissingTypeHints
class TestSession(object):
class TestSession:
@pytest.fixture(scope='module')
def app(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment