Move export thread so table can be refreshed

This commit is contained in:
JonnyWong16 2020-08-03 21:11:42 -07:00
parent 43fefcf748
commit a7eb563c2e
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 27 additions and 11 deletions

View file

@ -21,6 +21,7 @@ from future.builtins import str
import csv
import json
import os
import threading
from functools import partial
from io import open
@ -904,8 +905,6 @@ def export(section_id=None, rating_key=None, file_format='json'):
return
filename = helpers.clean_filename(filename)
filepath = get_export_filepath(filename)
logger.info("Tautulli Exporter :: Starting export for '%s'...", filename)
export_id = add_export(timestamp=timestamp,
section_id=section_id,
@ -918,6 +917,22 @@ def export(section_id=None, rating_key=None, file_format='json'):
return
attrs = MEDIA_TYPES[media_type]
threading.Thread(target=_real_export,
kwargs={'export_id': export_id,
'items': items,
'attrs': attrs,
'file_format': file_format,
'filename': filename}).start()
return True
def _real_export(export_id, items, attrs, file_format, filename):
logger.info("Tautulli Exporter :: Starting export for '%s'...", filename)
filepath = get_export_filepath(filename)
part = partial(helpers.get_attrs_to_dict, attrs=attrs)
pool = ThreadPool(processes=4)
success = True
@ -951,7 +966,7 @@ def export(section_id=None, rating_key=None, file_format='json'):
import traceback
traceback.print_exc()
set_export_state(export_id=export_id, success=False)
logger.error("Tautulli Exporter :: Failed exported to '%s': %s", filename, e)
logger.error("Tautulli Exporter :: Failed to export '%s': %s", filename, e)
success = False
finally:

View file

@ -6498,21 +6498,21 @@ class WebInterface(object):
rating_key (int): The rating key of the media item to export
Optional parameters:
None
file_format (str): 'json' (default) or 'csv'
Returns:
json:
{"result": "success",
"message": "Metadata export has started. Check the logs to monitor any problems."
"message": "Metadata export has started."
}
```
"""
threading.Thread(target=exporter.export,
kwargs={'section_id': section_id,
'rating_key': rating_key,
'file_format': file_format}).start()
return {'result': 'success',
'message': 'Metadata export has started. Check the logs to monitor any problems.'}
result = exporter.export(section_id=section_id, rating_key=rating_key, file_format=file_format)
if result:
return {'result': 'success', 'message': 'Metadata export has started.'}
else:
return {'result': 'error', 'message': 'Failed to export metadata.'}
@cherrypy.expose
@requireAuth(member_of("admin"))
@ -6532,6 +6532,7 @@ class WebInterface(object):
```
"""
result = exporter.get_export(export_id=row_id)
if result and result['complete'] == 1 and result['exists']:
return serve_download(exporter.get_export_filepath(result['filename']), name=result['filename'])
else: