Exemplo n.º 1
0
def update_messages(messages, session=None):
    """
    Update all messages status with the given IDs.

    :param messages: The messages to be updated as a list of dictionaries.
    """
    return orm_messages.update_messages(messages=messages, session=session)
Exemplo n.º 2
0
def update_processing_contents(processing_update,
                               content_updates,
                               update_messages=None,
                               session=None):
    """
    Update processing with contents.

    :param processing_update: dict with processing id and parameters.
    :param content_updates: list of content files.
    """
    if content_updates:
        orm_contents.update_contents(content_updates, session=session)
    if processing_update:
        orm_processings.update_processing(
            processing_id=processing_update['processing_id'],
            parameters=processing_update['parameters'],
            session=session)
    if update_messages:
        orm_messages.update_messages(update_messages, session=session)
Exemplo n.º 3
0
def update_request_with_transforms(request_id,
                                   parameters,
                                   new_transforms=None,
                                   update_transforms=None,
                                   new_messages=None,
                                   update_messages=None,
                                   session=None):
    """
    update an request.

    :param request_id: the request id.
    :param parameters: A dictionary of parameters.
    :param new_transforms: list of transforms
    :param update_transforms: list of transforms
    """
    if new_transforms:
        for tf in new_transforms:
            # tf_id = orm_transforms.add_transform(**tf, session=session)
            # original_work = tf['transform_metadata']['original_work']
            # del tf['transform_metadata']['original_work']
            workflow = tf['transform_metadata']['workflow']
            del tf['transform_metadata']['workflow']

            work = tf['transform_metadata']['work']
            tf_copy = copy.deepcopy(tf)
            tf_id = orm_transforms.add_transform(**tf_copy, session=session)
            tf['transform_id'] = tf_id

            # work = tf['transform_metadata']['work']
            # original_work.set_work_id(tf_id, transforming=True)
            # original_work.set_status(WorkStatus.New)
            work.set_work_id(tf_id, transforming=True)
            work.set_status(WorkStatus.New)
            workflow.refresh_works()

            collections = generate_collections(tf)
            for coll in collections:
                collection = coll['collection']
                del coll['collection']
                coll['transform_id'] = tf_id
                coll_id = orm_collections.add_collection(**coll,
                                                         session=session)
                # work.set_collection_id(coll, coll_id)
                collection.coll_id = coll_id

            # update transform to record the coll_id
            work.refresh_work()
            orm_transforms.update_transform(
                transform_id=tf_id,
                parameters={'transform_metadata': tf['transform_metadata']},
                session=session)

    if update_transforms:
        for tr_id in update_transforms:
            orm_transforms.update_transform(
                transform_id=tr_id,
                parameters=update_transforms[tr_id],
                session=session)

    if new_messages:
        orm_messages.add_messages(new_messages, session=session)
    if update_messages:
        orm_messages.update_messages(update_messages, session=session)
    return orm_requests.update_request(request_id, parameters, session=session)
Exemplo n.º 4
0
def add_transform_outputs(transform,
                          transform_parameters,
                          input_collections=None,
                          output_collections=None,
                          log_collections=None,
                          update_input_collections=None,
                          update_output_collections=None,
                          update_log_collections=None,
                          new_contents=None,
                          update_contents=None,
                          new_processing=None,
                          update_processing=None,
                          messages=None,
                          update_messages=None,
                          message_bulk_size=10000,
                          session=None):
    """
    For input contents, add corresponding output contents.

    :param transform: the transform.
    :param input_collections: The new input collections.
    :param output_collections: The new output collections.
    :param log_collections: The new log collections.
    :param update_input_collections: The updated input collections.
    :param update_output_collections: The updated output collections.
    :param update_log_collections: The updated log collections.
    :param new_contents: The new contents.
    :param update_contents: The updated contents.
    :param new_processing: The new processing.
    :param messages: Messages.
    :param message_bulk_size: The message bulk size.
    :param session: The database session in use.

    :raises DatabaseException: If there is a database error.
    """
    work = transform['transform_metadata']['work']

    if input_collections:
        for coll in input_collections:
            collection = coll['collection']
            del coll['collection']
            coll_id = orm_collections.add_collection(**coll, session=session)
            # work.set_collection_id(coll, coll_id)
            collection.coll_id = coll_id
    if output_collections:
        for coll in output_collections:
            collection = coll['collection']
            del coll['collection']
            coll_id = orm_collections.add_collection(**coll, session=session)
            # work.set_collection_id(coll, coll_id)
            collection.coll_id = coll_id
    if log_collections:
        for coll in log_collections:
            collection = coll['collection']
            del coll['collection']
            coll_id = orm_collections.add_collection(**coll, session=session)
            # work.set_collection_id(coll, coll_id)
            collection.coll_id = coll_id

    if update_input_collections:
        update_input_colls = [
            coll.collection for coll in update_input_collections
        ]
        orm_collections.update_collections(update_input_colls, session=session)
    if update_output_collections:
        update_output_colls = [
            coll.collection for coll in update_output_collections
        ]
        orm_collections.update_collections(update_output_colls,
                                           session=session)
    if update_log_collections:
        update_log_colls = [coll.collection for coll in update_log_collections]
        orm_collections.update_collections(update_log_colls, session=session)

    if new_contents:
        orm_contents.add_contents(new_contents, session=session)
    if update_contents:
        orm_contents.update_contents(update_contents, session=session)

    processing_id = None
    if new_processing:
        # print(new_processing)
        processing_id = orm_processings.add_processing(**new_processing,
                                                       session=session)
    if update_processing:
        for proc_id in update_processing:
            orm_processings.update_processing(
                processing_id=proc_id,
                parameters=update_processing[proc_id],
                session=session)

    if messages:
        if not type(messages) in [list, tuple]:
            messages = [messages]
        # for message in messages:
        #     orm_messages.add_message(msg_type=message['msg_type'],
        #                              status=message['status'],
        #                              source=message['source'],
        #                              request_id=message['request_id'],
        #                              workload_id=message['workload_id'],
        #                              transform_id=message['transform_id'],
        #                              num_contents=message['num_contents'],
        #                              msg_content=message['msg_content'],
        #                              bulk_size=message_bulk_size,
        #                              session=session)
        orm_messages.add_messages(messages, session=session)
    if update_messages:
        orm_messages.update_messages(update_messages, session=session)

    if transform:
        if processing_id:
            # work.set_processing_id(new_processing, processing_id)
            work.set_processing_id(
                new_processing['processing_metadata']['processing'],
                processing_id)
        work.refresh_work()
        orm_transforms.update_transform(transform_id=transform['transform_id'],
                                        parameters=transform_parameters,
                                        session=session)