Commit ecd29efb authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

preparing skeleton for sending tasks to celery

parent 1c34d00e
Pipeline #1313 failed with stage
in 46 seconds
/analytics:
post:
summary: Launch analytical script
parameters:
- name: script
in: query
description: Analysis script to run
required: true
type: string
- name: arguments
in: query
description: String describing the arguments to the analysis script
required: true
type: string
responses:
201:
description: Created
schema:
type: object
properties:
job_id:
type: string
swagger: '2.0'
info:
title: Fractalis API
description: foobar
version: '0.1.0'
host: 127.0.0.1:8000
schemes:
- http
produces:
- application/json
paths:
/data:
post:
summary: Add data to current session
parameters:
- name: etl
in: query
description: ETL to use for moving data from source to Fractalis
required: false
type: string
- name: data
in: query
description: Data in Fractalis standard format
required: false
type: string
- name: action
in: query
description: Action to extract the data from the source system
required: false
type: string
responses:
201:
description: Accepted
schema:
type: object
properties:
data_id:
type: string
get:
summary: Get all completed and running ETLs for current session
responses:
200:
description: OK
schema:
type: array
items:
$ref: '#/definitions/ETLStatus'
/data/{data_id}:
parameters:
- name: data_id
in: path
description: ID given on launching an ETL
required: true
type: string
get:
summary: Get status of ETL associated with data_id
responses:
200:
description: OK
schema:
$ref: '#/definitions/ETLStatus'
/data/{data_id}/subsets:
parameters:
- name: data_id
in: path
description: ID given on launching an ETL
required: true
type: string
post:
summary: Create a new subset for the loaded data
parameters:
- name: subjects
in: query
description: List of subjects that define a new subset
required: true
type: string
responses:
201:
description: Created
schema:
type: object
properties:
subset_id:
type: integer
/data/{data_id}/subsets/{subset_id}:
parameters:
- name: data_id
in: path
description: ID given on launching an ETL
required: true
type: string
- name: subset_id
in: path
description: ID given when creating subset
required: true
type: string
delete:
summary: Delete subset definition
responses:
200:
description: OK
/analytics:
post:
summary: Launch analytical script
parameters:
- name: script
in: query
description: Analysis script to run
required: true
type: string
- name: arguments
in: query
description: String describing the arguments to the analysis script
required: true
type: string
responses:
201:
description: Created
schema:
type: object
properties:
job_id:
type: string
/analytics/{job_id}:
parameters:
- name: job_id
in: path
description: ID given on job creation
required: true
type: string
get:
summary: Get job status information for given job id
responses:
200:
description: OK
schema:
$ref: '#/definitions/JobStatus'
delete:
summary: Attempts to kill all processes assiated with the job
responses:
200:
description: OK
definitions:
ETLStatus:
type: object
properties:
data_id:
type: string
status:
type: string
JobStatus:
type: object
properties:
status:
type: string
message:
type: string
\ No newline at end of file
......@@ -9,8 +9,8 @@ from fractalis.config import configure_app
from fractalis.celery import init_celery
from fractalis.analytics.controllers import analytics
app = Flask(__name__)
configure_app(app)
celery = init_celery(app)
flask_app = Flask(__name__)
configure_app(flask_app)
celery_app = init_celery(flask_app)
app.register_blueprint(analytics, url_prefix='/analytics')
flask_app.register_blueprint(analytics, url_prefix='/analytics')
import json
import uuid
from flask import Blueprint
......@@ -8,7 +9,7 @@ analytics = Blueprint('analytics', __name__)
@analytics.route('', methods=['POST'])
def create_job():
body = json.dumps({'job_id': 123})
body = json.dumps({'job_id': str(uuid.uuid4())})
return body, 201
......
from fractalis import celery_app
def start_job():
pass
def cancel_job(job_id):
pass
def get_job_details(job_id):
pass
......@@ -31,13 +31,14 @@ def init_celery(app):
app.config['CELERY_BROKER_URL'])
raise ConnectionRefusedError(error_msg) from e
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
# -- Execute celery tasks in app context --
# TaskBase = celery.Task
#
# class ContextTask(TaskBase):
# abstract = True
#
# def __call__(self, *args, **kwargs):
# with app.app_context():
# return TaskBase.__call__(self, *args, **kwargs)
# celery.Task = ContextTask
return celery
......@@ -8,9 +8,11 @@ class TestAnalytics(object):
@pytest.fixture
def test_client(self):
import fractalis
fractalis.app.testing = True
test_client = fractalis.app.test_client()
from flask import Flask
from fractalis.config import configure_app
app = Flask('test_app')
configure_app(app, mode='testing')
test_client = app.test_client()
return test_client
def test_create_new_resource(self, test_client):
......@@ -21,7 +23,10 @@ class TestAnalytics(object):
assert uuid.UUID(response_body['job_id'])
assert test_client.head(new_resource_url).status_code == 200
def test_create_new_resource_with_invalid_parameters(self, test_client):
def test_create_new_resource_with_not_existing_script(self, test_client):
assert False
def test_create_new_resource_not_authenticated(self, test_client):
assert False
def test_delete_resource(self, test_client):
......@@ -31,12 +36,18 @@ class TestAnalytics(object):
assert test_client.delete(new_resource_url).status_code == 200
assert test_client.head(new_resource_url).status_code == 404
def test_delete_resource_not_authenticated(self, test_client):
assert False
def test_delete_not_existing_resource(self, test_client):
assert False
def test_get_status_running(self, test_client):
assert False
def test_get_status_not_authenticated(self, test_client):
assert False
def test_get_status_if_script_failure(self, test_client):
assert False
......
......@@ -11,26 +11,26 @@ class TestConfig(object):
def test_config_when_test_mode(self):
os.environ['FRACTALIS_MODE'] = 'testing'
reload(fractalis)
assert not fractalis.app.config['DEBUG']
assert fractalis.app.config['TESTING']
assert not fractalis.flask_app.config['DEBUG']
assert fractalis.flask_app.config['TESTING']
def test_config_when_development_mode(self):
os.environ['FRACTALIS_MODE'] = 'development'
reload(fractalis)
assert fractalis.app.config['DEBUG']
assert not fractalis.app.config['TESTING']
assert fractalis.flask_app.config['DEBUG']
assert not fractalis.flask_app.config['TESTING']
def test_config_when_production_mode(self):
os.environ['FRACTALIS_MODE'] = 'production'
reload(fractalis)
assert not fractalis.app.config['DEBUG']
assert not fractalis.app.config['TESTING']
assert not fractalis.flask_app.config['DEBUG']
assert not fractalis.flask_app.config['TESTING']
def test_config_when_default(self):
del os.environ['FRACTALIS_MODE']
reload(fractalis)
assert not fractalis.app.config['DEBUG']
assert not fractalis.app.config['TESTING']
assert not fractalis.flask_app.config['DEBUG']
assert not fractalis.flask_app.config['TESTING']
def test_config_when_unknown_mode(self):
os.environ['FRACTALIS_MODE'] = 'foobar'
......
import pytest
class TestJob(object):
Supports Markdown
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