mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-13 08:42:59 -07:00
Move export thread so table can be refreshed
This commit is contained in:
parent
43fefcf748
commit
a7eb563c2e
2 changed files with 27 additions and 11 deletions
|
@ -21,6 +21,7 @@ from future.builtins import str
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import threading
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from io import open
|
from io import open
|
||||||
|
@ -904,8 +905,6 @@ def export(section_id=None, rating_key=None, file_format='json'):
|
||||||
return
|
return
|
||||||
|
|
||||||
filename = helpers.clean_filename(filename)
|
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,
|
export_id = add_export(timestamp=timestamp,
|
||||||
section_id=section_id,
|
section_id=section_id,
|
||||||
|
@ -918,6 +917,22 @@ def export(section_id=None, rating_key=None, file_format='json'):
|
||||||
return
|
return
|
||||||
|
|
||||||
attrs = MEDIA_TYPES[media_type]
|
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)
|
part = partial(helpers.get_attrs_to_dict, attrs=attrs)
|
||||||
pool = ThreadPool(processes=4)
|
pool = ThreadPool(processes=4)
|
||||||
success = True
|
success = True
|
||||||
|
@ -951,7 +966,7 @@ def export(section_id=None, rating_key=None, file_format='json'):
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
set_export_state(export_id=export_id, success=False)
|
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
|
success = False
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -6498,21 +6498,21 @@ class WebInterface(object):
|
||||||
rating_key (int): The rating key of the media item to export
|
rating_key (int): The rating key of the media item to export
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
None
|
file_format (str): 'json' (default) or 'csv'
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
json:
|
json:
|
||||||
{"result": "success",
|
{"result": "success",
|
||||||
"message": "Metadata export has started. Check the logs to monitor any problems."
|
"message": "Metadata export has started."
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
threading.Thread(target=exporter.export,
|
result = exporter.export(section_id=section_id, rating_key=rating_key, file_format=file_format)
|
||||||
kwargs={'section_id': section_id,
|
|
||||||
'rating_key': rating_key,
|
if result:
|
||||||
'file_format': file_format}).start()
|
return {'result': 'success', 'message': 'Metadata export has started.'}
|
||||||
return {'result': 'success',
|
else:
|
||||||
'message': 'Metadata export has started. Check the logs to monitor any problems.'}
|
return {'result': 'error', 'message': 'Failed to export metadata.'}
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
|
@ -6532,6 +6532,7 @@ class WebInterface(object):
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
result = exporter.get_export(export_id=row_id)
|
result = exporter.get_export(export_id=row_id)
|
||||||
|
|
||||||
if result and result['complete'] == 1 and result['exists']:
|
if result and result['complete'] == 1 and result['exists']:
|
||||||
return serve_download(exporter.get_export_filepath(result['filename']), name=result['filename'])
|
return serve_download(exporter.get_export_filepath(result['filename']), name=result['filename'])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue