Esempio n. 1
0
def init_unit_of_work(q, store, unit_of_work, *args) -> Dict[str, Any]:
    """
    Function used directly in PyTaskIO class.
    :param q: The client task queue
    :param unit_of_work: python code to run
    :param args: Unit of work arguments
    :return:
    """
    serialized_uow = serialize_unit_of_work(unit_of_work, *args)
    # The unit of work gets saved to the store in case the task
    # fails and the client / user wants to retry
    uow_metadata = _create_store_key(
        _create_store_index(store),
        store,
        serialized_uow
    )

    # Unit of work gets push onto the task queue & metadata gets updated
    serialized_uow_meta = serialize_store_data(uow_metadata)
    # LPUSH returns the queue length after the push operation
    queue_length = q.lpush(_QUEUE_NAME, serialized_uow_meta)
    uow_metadata["queue_created"] = get_datetime_now()
    uow_metadata["queue_length"] = queue_length
    # Returns metadata back to the caller / user.
    return uow_metadata
Esempio n. 2
0
async def add_uof_result_to_store(executed_uow: Any, uow_metadata: Dict[str, Any], store) -> None:
    now = get_datetime_now()

    # Add serialized results to store
    uow_metadata["serialized_result"] = executed_uow
    uow_metadata["store_updated"] = now
    uow_metadata["result_exec_date"] = now

    serialized_metadata = serialize_store_data(uow_metadata)

    update_success = store.set(uow_metadata["store_name"], serialized_metadata)
    if not update_success:
        logger.error("PyTaskIO Error: Store was unsuccessful updating meta for unit of work.")
Esempio n. 3
0
def _create_store_key(current_index, store, serialized_data: bytes = None) -> Dict[str, Any]:
    uow_store_name = f"uow_result_#{current_index}"
    init_success = store.set(uow_store_name, 0)
    if not init_success:
        logger.error("PyTaskIO Error: Store was unsuccessful creating registry for unit of work.")
    uow_metadata = _create_uow_metadata(
        uow_store_name,
        current_index,
        get_datetime_now(),
        serialized_data,
    )

    serialized_uow_meta = serialize_store_data(uow_metadata)
    update_success = store.set(uow_store_name, serialized_uow_meta)
    if not update_success:
        logger.error("PyTaskIO Error: Store was unsuccessful updating meta for unit of work.")
    return uow_metadata