from __future__ import absolute_import, unicode_literals
from .celery import app
from .xlsprocessor import handle_dict
from .models import Document


@app.task()
def process_xls_file(doc_id):
    doc = Document.objects.get(id=doc_id)
    doc.status = 1
    doc.save()
    try:
        handle_dict(doc.document)
        doc.status = 2
        doc.save()
    except Exception as e:
        print(f'{str(e)}')
        doc.status = -1
        doc.save()
