#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 30 13:05:54 2022

@author: elena
"""

#from django.conf import settings

from receipe.consumer import Consumer, ConsumerError

def consume_file(path,
                 applyBinarize=True,
                 debug=False,
                 task_id=None,
                 scannerFile=False):

    print("Start consuming from task")
    receipe = Consumer().try_consume_file(
        path,
        applyBinarize=applyBinarize,
        debug=debug,
        task_id=task_id,
        scannerFile=scannerFile
    )

    if receipe:
        return "Success. New document id {} created".format(
            receipe.pk
        )
    else:
        raise ConsumerError("Unknown error: Returned document was null, but "
                            "no error message was given.")
