kopia lustrzana https://github.com/OpenDroneMap/WebODM
Fixed cleanup
rodzic
ab21804dbb
commit
4a6e56bf8b
|
@ -262,6 +262,8 @@ class CheckUrlTaskView(TaskView):
|
||||||
else:
|
else:
|
||||||
return Response({'ddbUrl': data['ddbWebUrl']}, status=status.HTTP_200_OK)
|
return Response({'ddbUrl': data['ddbWebUrl']}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def get_status_key(task_id):
|
||||||
|
return '{}_ddb'.format(task_id)
|
||||||
|
|
||||||
@receiver(plugin_signals.task_removed, dispatch_uid="ddb_on_task_removed")
|
@receiver(plugin_signals.task_removed, dispatch_uid="ddb_on_task_removed")
|
||||||
@receiver(plugin_signals.task_completed, dispatch_uid="ddb_on_task_completed")
|
@receiver(plugin_signals.task_completed, dispatch_uid="ddb_on_task_completed")
|
||||||
|
@ -274,28 +276,25 @@ def ddb_cleanup(sender, task_id, **kwargs):
|
||||||
|
|
||||||
logger.info("Cleaning up DroneDB datastore for task {}".format(str(task_id)))
|
logger.info("Cleaning up DroneDB datastore for task {}".format(str(task_id)))
|
||||||
|
|
||||||
task = models.Task.objects.get(id=task_id)
|
|
||||||
project_pk = task.project.id
|
|
||||||
|
|
||||||
datastore = get_current_plugin().get_global_data_store()
|
datastore = get_current_plugin().get_global_data_store()
|
||||||
combined_id = "{}_{}_ddb".format(project_pk, task_id)
|
status_key = get_status_key(task_id)
|
||||||
|
|
||||||
logger.info("Info task {0}, project {1} ({2})".format(str(task_id), str(project_pk), combined_id))
|
logger.info("Info task {0} ({1})".format(str(task_id), status_key))
|
||||||
|
|
||||||
datastore.del_key(combined_id)
|
datastore.del_key(status_key)
|
||||||
# task.project
|
|
||||||
|
|
||||||
class StatusTaskView(TaskView):
|
class StatusTaskView(TaskView):
|
||||||
def get(self, request, project_pk, pk):
|
def get(self, request, pk):
|
||||||
|
|
||||||
task = self.get_and_check_task(request, pk)
|
task = self.get_and_check_task(request, pk)
|
||||||
|
|
||||||
# Associate the folder url with the project and task
|
# Associate the folder url with the project and task
|
||||||
combined_id = "{}_{}_ddb".format(project_pk, pk)
|
status_key = get_status_key(pk)
|
||||||
|
|
||||||
datastore = get_current_plugin().get_global_data_store()
|
datastore = get_current_plugin().get_global_data_store()
|
||||||
|
|
||||||
task_info = datastore.get_json(combined_id, {
|
task_info = datastore.get_json(status_key, {
|
||||||
'status': 0, # Idle
|
'status': 0, # Idle
|
||||||
'shareUrl': None,
|
'shareUrl': None,
|
||||||
'uploadedFiles': 0,
|
'uploadedFiles': 0,
|
||||||
|
@ -322,13 +321,13 @@ DRONEDB_ASSETS = [
|
||||||
'ground_control_points.geojson'
|
'ground_control_points.geojson'
|
||||||
]
|
]
|
||||||
class ShareTaskView(TaskView):
|
class ShareTaskView(TaskView):
|
||||||
def post(self, request, project_pk, pk):
|
def post(self, request, pk):
|
||||||
|
|
||||||
from app.plugins import logger
|
from app.plugins import logger
|
||||||
|
|
||||||
task = self.get_and_check_task(request, pk)
|
task = self.get_and_check_task(request, pk)
|
||||||
|
|
||||||
combined_id = "{}_{}_ddb".format(project_pk, pk)
|
status_key = get_status_key(pk)
|
||||||
|
|
||||||
datastore = get_current_plugin().get_global_data_store()
|
datastore = get_current_plugin().get_global_data_store()
|
||||||
|
|
||||||
|
@ -342,33 +341,29 @@ class ShareTaskView(TaskView):
|
||||||
'error': None
|
'error': None
|
||||||
}
|
}
|
||||||
|
|
||||||
datastore.set_json(combined_id, data)
|
datastore.set_json(status_key, data)
|
||||||
|
|
||||||
settings = get_settings(request)
|
settings = get_settings(request)
|
||||||
|
|
||||||
available_assets = [task.get_asset_file_or_zipstream(f) for f in list(set(task.available_assets) & set(DRONEDB_ASSETS))]
|
available_assets = [task.get_asset_file_or_zipstream(f) for f in list(set(task.available_assets) & set(DRONEDB_ASSETS))]
|
||||||
|
|
||||||
logger.info(available_assets)
|
|
||||||
|
|
||||||
files = [{'path': f[0], 'name': f[0].split('/')[-1], 'size': os.path.getsize(f[0])} for f in available_assets]
|
files = [{'path': f[0], 'name': f[0].split('/')[-1], 'size': os.path.getsize(f[0])} for f in available_assets]
|
||||||
|
|
||||||
logger.info(files)
|
share_to_ddb.delay(pk, settings, files)
|
||||||
|
|
||||||
share_to_ddb.delay(project_pk, pk, settings, files)
|
|
||||||
|
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def share_to_ddb(project_pk, pk, settings, files):
|
def share_to_ddb(pk, settings, files):
|
||||||
|
|
||||||
from app.plugins import logger
|
from app.plugins import logger
|
||||||
|
|
||||||
# task_info['sharing'] = False
|
# task_info['sharing'] = False
|
||||||
# set_task_info(task_id, task_info)
|
# set_task_info(task_id, task_info)
|
||||||
|
|
||||||
combined_id = "{}_{}_ddb".format(project_pk, pk)
|
status_key = get_status_key(pk)
|
||||||
datastore = get_current_plugin().get_global_data_store()
|
datastore = get_current_plugin().get_global_data_store()
|
||||||
|
|
||||||
registry_url, username, password, token = settings
|
registry_url, username, password, token = settings
|
||||||
|
@ -378,12 +373,12 @@ def share_to_ddb(project_pk, pk, settings, files):
|
||||||
# Init share (to check)
|
# Init share (to check)
|
||||||
share_token = ddb.share_init()
|
share_token = ddb.share_init()
|
||||||
|
|
||||||
status = datastore.get_json(combined_id)
|
status = datastore.get_json(status_key)
|
||||||
|
|
||||||
status['totalFiles'] = len(files)
|
status['totalFiles'] = len(files)
|
||||||
status['totalSize'] = sum(i['size'] for i in files)
|
status['totalSize'] = sum(i['size'] for i in files)
|
||||||
|
|
||||||
datastore.set_json(combined_id, status)
|
datastore.set_json(status_key, status)
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
|
|
||||||
|
@ -393,10 +388,13 @@ def share_to_ddb(project_pk, pk, settings, files):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
up = ddb.share_upload(share_token, file['path'], file['name'])
|
up = ddb.share_upload(share_token, file['path'], file['name'])
|
||||||
|
|
||||||
logger.info("Uploaded " + file['name'])
|
logger.info("Uploaded " + file['name'])
|
||||||
|
|
||||||
status['uploadedFiles'] += 1
|
status['uploadedFiles'] += 1
|
||||||
status['uploadedSize'] += file['size']
|
status['uploadedSize'] += file['size']
|
||||||
datastore.set_json(combined_id, status)
|
|
||||||
|
datastore.set_json(status_key, status)
|
||||||
|
|
||||||
res = ddb.share_commit(share_token)
|
res = ddb.share_commit(share_token)
|
||||||
|
|
||||||
|
@ -405,5 +403,5 @@ def share_to_ddb(project_pk, pk, settings, files):
|
||||||
|
|
||||||
logger.info("Shared on url " + status['shareUrl'])
|
logger.info("Shared on url " + status['shareUrl'])
|
||||||
|
|
||||||
datastore.set_json(combined_id, status)
|
datastore.set_json(status_key, status)
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ class Plugin(PluginBase):
|
||||||
return [
|
return [
|
||||||
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/import", ImportDatasetTaskView.as_view()),
|
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/import", ImportDatasetTaskView.as_view()),
|
||||||
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/checkforurl", CheckUrlTaskView.as_view()),
|
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/checkforurl", CheckUrlTaskView.as_view()),
|
||||||
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/status", StatusTaskView.as_view()),
|
MountPoint("tasks/(?P<pk>[^/.]+)/status", StatusTaskView.as_view()),
|
||||||
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/share", ShareTaskView.as_view()),
|
MountPoint("tasks/(?P<pk>[^/.]+)/share", ShareTaskView.as_view()),
|
||||||
MountPoint("checkcredentials", CheckCredentialsTaskView.as_view()),
|
MountPoint("checkcredentials", CheckCredentialsTaskView.as_view()),
|
||||||
MountPoint("organizations/(?P<org>[^/.]+)/datasets/(?P<ds>[^/.]+)/folders", FoldersTaskView.as_view()),
|
MountPoint("organizations/(?P<org>[^/.]+)/datasets/(?P<ds>[^/.]+)/folders", FoldersTaskView.as_view()),
|
||||||
MountPoint("organizations/(?P<org>[^/.]+)/datasets", DatasetsTaskView.as_view()),
|
MountPoint("organizations/(?P<org>[^/.]+)/datasets", DatasetsTaskView.as_view()),
|
||||||
|
|
|
@ -25,8 +25,8 @@ const BUTTON_TEXT_MAPPER = [
|
||||||
'Share to DroneDB',
|
'Share to DroneDB',
|
||||||
// Running
|
// Running
|
||||||
'Sharing...',
|
'Sharing...',
|
||||||
// Error
|
// Error retry
|
||||||
'Error',
|
'Error, retry',
|
||||||
// Done
|
// Done
|
||||||
'View on DroneDB'
|
'View on DroneDB'
|
||||||
];
|
];
|
||||||
|
@ -60,7 +60,7 @@ export default class ShareButton extends React.Component{
|
||||||
const { task } = this.props;
|
const { task } = this.props;
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: `/api/plugins/dronedb/projects/${task.project}/tasks/${task.id}/status`,
|
url: `/api/plugins/dronedb/tasks/${task.id}/status`,
|
||||||
contentType: 'application/json'
|
contentType: 'application/json'
|
||||||
}).done(taskInfo => {
|
}).done(taskInfo => {
|
||||||
this.setState({taskInfo});
|
this.setState({taskInfo});
|
||||||
|
@ -78,7 +78,7 @@ export default class ShareButton extends React.Component{
|
||||||
const { task } = this.props;
|
const { task } = this.props;
|
||||||
|
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
url: `/api/plugins/dronedb/projects/${task.project}/tasks/${task.id}/share`,
|
url: `/api/plugins/dronedb/tasks/${task.id}/share`,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
//data: JSON.stringify({
|
//data: JSON.stringify({
|
||||||
// oamParams: oamParams
|
// oamParams: oamParams
|
||||||
|
@ -140,7 +140,7 @@ export default class ShareButton extends React.Component{
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="share-button">
|
<div className="share-button">
|
||||||
<button className="btn btn-primary btn-sm" onClick={this.handleClick} disabled={this.state.taskInfo == null || this.state.taskInfo.error || this.state.taskInfo.status == 1 }>
|
<button className="btn btn-primary btn-sm" onClick={this.handleClick} disabled={this.state.taskInfo == null || this.state.taskInfo.status == STATE_RUNNING }>
|
||||||
<i className={getButtonIcon()}></i>
|
<i className={getButtonIcon()}></i>
|
||||||
{getButtonLabel()}
|
{getButtonLabel()}
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -89,8 +89,7 @@ export default class SelectUrlDialog extends Component {
|
||||||
});
|
});
|
||||||
|
|
||||||
$.get(`${this.props.apiURL}/info`)
|
$.get(`${this.props.apiURL}/info`)
|
||||||
.done(result => {
|
.done(result => {
|
||||||
console.log(result);
|
|
||||||
this.setState({info: result});
|
this.setState({info: result});
|
||||||
})
|
})
|
||||||
.fail((error) => {
|
.fail((error) => {
|
||||||
|
@ -99,7 +98,7 @@ export default class SelectUrlDialog extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleVerify = () => {
|
handleVerify = () => {
|
||||||
//console.log("Verify");
|
|
||||||
this.setState({verifyStatus: 'loading'});
|
this.setState({verifyStatus: 'loading'});
|
||||||
|
|
||||||
$.post(`${this.props.apiURL}/verifyurl`, { url: this.state.ddbUrl }).done(result => {
|
$.post(`${this.props.apiURL}/verifyurl`, { url: this.state.ddbUrl }).done(result => {
|
||||||
|
@ -139,8 +138,6 @@ export default class SelectUrlDialog extends Component {
|
||||||
folders: []
|
folders: []
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Load datasets of", e);
|
|
||||||
|
|
||||||
$.get(`${this.props.apiURL}/organizations/${e.value}/datasets`)
|
$.get(`${this.props.apiURL}/organizations/${e.value}/datasets`)
|
||||||
.done(result => {
|
.done(result => {
|
||||||
|
|
||||||
|
@ -177,8 +174,6 @@ export default class SelectUrlDialog extends Component {
|
||||||
folders: []
|
folders: []
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Load folders of", e);
|
|
||||||
|
|
||||||
$.get(`${this.props.apiURL}/organizations/${this.state.selectedOrganization.value}/datasets/${e.value}/folders`)
|
$.get(`${this.props.apiURL}/organizations/${this.state.selectedOrganization.value}/datasets/${e.value}/folders`)
|
||||||
.done(result => {
|
.done(result => {
|
||||||
|
|
||||||
|
@ -211,7 +206,7 @@ export default class SelectUrlDialog extends Component {
|
||||||
this.setState({selectedFolder: e, verifyStatus: null});
|
this.setState({selectedFolder: e, verifyStatus: null});
|
||||||
|
|
||||||
if (this.state.info == null || this.state.info.hubUrl == null) {
|
if (this.state.info == null || this.state.info.hubUrl == null) {
|
||||||
console.log("Cannot generate hub url");
|
console.warn("Cannot generate ddb url, no hub url");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue