Пример #1
0
def nmt_task(id):
    """ Task for automatically processing a translation.

    This task is responsible for requesting the Marian-NMT server to
    translate a given text from English to Spanish.

    The Translation aggregate is already created and persisted, so this
    task must fetch its data. If for some reason the application goes
    down, it's possible to reprocess "requested" translations adding
    their IDs to the workers queue.

    Args:
        id (string): The translation aggregate UUID4 string.
    """
    translation = repository.get(id)
    translation = translator.nmt_process(translation)
    repository.save(translation)
    projections_task.send(id)
Пример #2
0
def callback(id=None):
    """Callback route to update a Translation resource.

    This route is used by an external translation service to notify it
    finished processing a text.

    Args:
        id (str): The Translation aggregate ID to update it.

    """
    if id:
        logger.debug(f'processing POST "/callback/{id}"')
        translation = repository.get(id)
        translation = translator.get(translation)
        repository.save(translation)
        tasks.projections_task.send(id)
        return jsonify(success=True)

    return jsonify(error=404, text="Resource not found.")
Пример #3
0
def translation_task(id):
    """ Task for processing a translation.

    This task is responsible for requesting the translation service to
    translated a given text from English to Spanish.

    The Translation aggregate is already created and persisted, so this
    task must fetch its data. If for some reason the application goes
    down, it's possible to reprocess "requested" translations adding
    their IDs to the workers queue.

    After sending a request to the translation service, this worker will
    persist a tracking identifier and poll this translation until it's
    finished.

    Args:
        id (string): The translation aggregate UUID4 string.
    """
    translation = repository.get(id)
    translation = translator.process(translation)
    repository.save(translation)
    projections_task.send(id)