Skip to content

Commit

Permalink
Merge branch 'feature/taskout' into 'develop'
Browse files Browse the repository at this point in the history
add output_location when creating task

See merge request core/sevenbridges-python!100
  • Loading branch information
borislavd88 committed Jul 14, 2022
2 parents e028642 + e91a747 commit fb98173
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,8 @@ the ``batch_by`` criteria.

``execution_settings`` - Execution settings for the task.

``output_location`` - Location where task outputs will be stored.

``execution_status`` - Task execution status.

``price`` - Task cost.
Expand Down
8 changes: 7 additions & 1 deletion sevenbridges/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Task(Resource):
inputs = CompoundField(Input, read_only=False)
outputs = CompoundField(Output, read_only=True)
execution_settings = DictField(read_only=True)
output_location = DictField(read_only=True)
use_interruptible_instances = BooleanField(read_only=False)
origin = StringField(read_only=True, name='origin_id')

Expand Down Expand Up @@ -141,7 +142,7 @@ def query(cls, project=None, status=None, batch=None,
def create(cls, name, project, app, revision=None, batch_input=None,
batch_by=None, inputs=None, description=None, run=False,
disable_batch=False, interruptible=None,
execution_settings=None, api=None):
execution_settings=None, output_location=None, api=None):

"""
Creates a task on server.
Expand All @@ -157,6 +158,8 @@ def create(cls, name, project, app, revision=None, batch_input=None,
:param disable_batch: If True disables batching of a batch task.
:param interruptible: If True interruptible instance will be used.
:param execution_settings: Execution settings for the task.
:param output_location: Dictionary that allows you to define the exact
location where your task outputs will be stored.
:param api: Api instance.
:return: Task object.
:raises: TaskValidationError if validation Fails.
Expand Down Expand Up @@ -199,6 +202,9 @@ def create(cls, name, project, app, revision=None, batch_input=None,
if execution_settings:
task_data.update({'execution_settings': execution_settings})

if output_location:
task_data.update({'output_location': output_location})

if run:
params.update({'action': 'run'})

Expand Down
41 changes: 41 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,47 @@ def test_create_task(api, given, verifier, run):
verifier.task.task_created()


@pytest.mark.parametrize("run", [True, False])
def test_create_task_with_output_location(api, given, verifier, run):
# preconditions
owner = generator.user_name()
project_short_name = generator.slug()
project_id = f'{owner}/{project_short_name}'
given.project.exists(id=project_id)
given.file.files_exist_for_project(project_id, 10)
app_id = f'{owner}/{project_short_name}/app-name'
batch_by = {'type': 'item'}

project = api.projects.get(id=project_id)
files = api.files.query(project=project)
inputs = {
'FastQC': files,
'reads': False,
'some_file': files[0],
'record_input': {"string": "string_input", "file": files[0]}
}
output_location = {
'main_location': '/Analysis/<task_id>_<task_name>/',
'nodes_location': {'b64html': {
'output_location': '/Analysis/<task_id>_<task_name>/'}
}
}

given.task.can_be_created(
batch_by=batch_by, batch_input='FastQC', app=app_id, project=project.id
)
# action
task = api.tasks.create(
generator.name(), project, app_id, batch_input='FastQC',
batch_by=batch_by, inputs=inputs, run=run,
output_location=output_location
)

# verification
assert repr(task)
verifier.task.task_created()


@pytest.mark.parametrize("run", [True, False])
def test_create_task_with_errors(api, given, verifier, run):
# preconditions
Expand Down

0 comments on commit fb98173

Please sign in to comment.