Example #1
0
def task_create(session, values):
    tags = values.pop("tags", [])
    # TODO(ikhudoshyn): currently 'input_task'
    # does not come in 'values'
    # After completely switching to the new
    # DB schema in API we should reconstruct
    # input_task's from associated workloads
    # the same is true for 'pass_sla',
    # 'task_duration', 'validation_result'
    # and 'validation_duration'
    task = models.Task(**values)
    session.add(task)
    session.commit()
    task = task.as_dict()

    if tags:
        session.bulk_save_objects(
            models.Tag(uuid=task["uuid"], tag=t, type=consts.TagType.TASK)
            for t in set(tags))
    task["tags"] = tags
    return task
Example #2
0
def task_create(values):
    tags = values.pop("tags", [])
    # TODO(ikhudoshyn): currently 'input_task'
    # does not come in 'values'
    # After completely switching to the new
    # DB schema in API we should reconstruct
    # input_task's from associated workloads
    # the same is true for 'pass_sla',
    # 'task_duration', 'validation_result'
    # and 'validation_duration'
    task = models.Task()
    task.update(values)
    task.save(get_session())

    if tags:
        get_session().bulk_save_objects(
            models.Tag(uuid=task.uuid, tag=t, type=consts.TagType.TASK)
            for t in set(tags))
        task.tags = sorted(_tags_get(task.uuid, consts.TagType.TASK))
    else:
        task.tags = []
    return task