🐛 pmgr: make upload install async & fix conflict handling
It turns out that a) we were not yet doing plugin installation after an archive/file upload asynchronously, so that any delays there could still cause timeouts, and that b) we were also not handling the conflict situation of trying to start another plugin install while one is already running correctly on the frontend. This fixes both issues.
This commit is contained in:
1 parent
99360762d9
commit
35c3660958
2 files changed
+93
-46
No files matched your search
@@ -380,28 +380,43 @@ class PluginManagerPlugin(
|
||||
)
|
||||
|
||||
ext = exts[0]
|
||||
archive = tempfile.NamedTemporaryFile(delete=False, suffix=ext)
|
||||
archive.close()
|
||||
shutil.copy(upload_path, archive.name)
|
||||
|
||||
archive = tempfile.NamedTemporaryFile(
|
||||
delete=False, suffix="{ext}".format(**locals())
|
||||
)
|
||||
try:
|
||||
archive.close()
|
||||
shutil.copy(upload_path, archive.name)
|
||||
return self.command_install(
|
||||
path=archive.name,
|
||||
name=upload_name,
|
||||
force="force" in flask.request.values
|
||||
and flask.request.values["force"] in valid_boolean_trues,
|
||||
)
|
||||
finally:
|
||||
def perform_install(source, name, force=False):
|
||||
try:
|
||||
os.remove(archive.name)
|
||||
except Exception as e:
|
||||
self._logger.warning(
|
||||
"Could not remove temporary file {path} again: {message}".format(
|
||||
path=archive.name, message=str(e)
|
||||
)
|
||||
self.command_install(
|
||||
path=source,
|
||||
name=name,
|
||||
force=force,
|
||||
)
|
||||
finally:
|
||||
try:
|
||||
os.remove(archive.name)
|
||||
except Exception as e:
|
||||
self._logger.warning(
|
||||
"Could not remove temporary file {path} again: {message}".format(
|
||||
path=archive.name, message=str(e)
|
||||
)
|
||||
)
|
||||
|
||||
with self._install_lock:
|
||||
if self._install_task is not None:
|
||||
return make_response("There's already a plugin being installed", 409)
|
||||
|
||||
self._install_task = threading.Thread(
|
||||
target=perform_install,
|
||||
args=(archive.name, upload_name),
|
||||
kwargs={
|
||||
"force": "force" in flask.request.values
|
||||
and flask.request.values["force"] in valid_boolean_trues
|
||||
},
|
||||
)
|
||||
self._install_task.daemon = True
|
||||
self._install_task.start()
|
||||
|
||||
return jsonify(in_progress=True)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/export", methods=["GET"])
|
||||
@no_firstrun_access
|
||||
@@ -538,7 +553,7 @@ class PluginManagerPlugin(
|
||||
|
||||
with self._install_lock:
|
||||
if self._install_task is not None:
|
||||
return make_response("There's always a plugin being installed", 409)
|
||||
return make_response("There's already a plugin being installed", 409)
|
||||
|
||||
self._install_task = threading.Thread(
|
||||
target=self.command_install,
|
||||
@@ -636,7 +651,7 @@ class PluginManagerPlugin(
|
||||
|
||||
# determine type of path
|
||||
if self._is_archive(path):
|
||||
return self._command_install_archive(
|
||||
result = self._command_install_archive(
|
||||
path,
|
||||
source=source,
|
||||
source_type=source_type,
|
||||
@@ -646,12 +661,13 @@ class PluginManagerPlugin(
|
||||
)
|
||||
|
||||
elif self._is_pythonfile(path):
|
||||
return self._command_install_pythonfile(
|
||||
result = self._command_install_pythonfile(
|
||||
path, source=source, source_type=source_type, name=name
|
||||
)
|
||||
|
||||
else:
|
||||
raise exceptions.InvalidPackageFormat()
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
self._logger.error("Could not fetch plugin from server, got {}".format(e))
|
||||
result = {
|
||||
@@ -661,7 +677,7 @@ class PluginManagerPlugin(
|
||||
"reason": "Could not fetch plugin from server, got {}".format(e),
|
||||
}
|
||||
self._send_result_notification("install", result)
|
||||
return result
|
||||
|
||||
except exceptions.InvalidPackageFormat:
|
||||
self._logger.error(
|
||||
"{} is neither an archive nor a python file, can't install that.".format(
|
||||
@@ -676,12 +692,29 @@ class PluginManagerPlugin(
|
||||
"a plugin archive nor a single file plugin".format(source),
|
||||
}
|
||||
self._send_result_notification("install", result)
|
||||
return result
|
||||
|
||||
except Exception:
|
||||
error_msg = (
|
||||
"Unexpected error while trying to install plugin from {}".format(
|
||||
source
|
||||
)
|
||||
)
|
||||
self._logger.exception(error_msg)
|
||||
result = {
|
||||
"result": False,
|
||||
"source": source,
|
||||
"source_type": source_type,
|
||||
"reason": error_msg,
|
||||
}
|
||||
self._send_result_notification("install", result)
|
||||
|
||||
finally:
|
||||
if folder is not None:
|
||||
folder.cleanup()
|
||||
self._install_task = None
|
||||
|
||||
return result
|
||||
|
||||
# noinspection DuplicatedCode
|
||||
def _command_install_archive(
|
||||
self,
|
||||
@@ -702,7 +735,7 @@ class PluginManagerPlugin(
|
||||
# currently throttled, we refuse to run
|
||||
error_msg = (
|
||||
"System is currently throttled, refusing to install anything"
|
||||
" due to possible stability isssues"
|
||||
" due to possible stability issues"
|
||||
)
|
||||
self._logger.error(error_msg)
|
||||
result = {
|
||||
|
||||
@@ -435,23 +435,30 @@ $(function () {
|
||||
},
|
||||
done: function (e, data) {
|
||||
var response = data.result;
|
||||
if (response.result) {
|
||||
self._markDone();
|
||||
} else {
|
||||
self._markDone(response.reason);
|
||||
if (!response.in_progress) {
|
||||
if (response.result) {
|
||||
self._markDone();
|
||||
} else {
|
||||
self._markDone(response.reason);
|
||||
}
|
||||
}
|
||||
|
||||
self.uploadButton.unbind("click");
|
||||
self.uploadFilename(undefined);
|
||||
},
|
||||
fail: function (e, data) {
|
||||
new PNotify({
|
||||
title: gettext("Something went wrong"),
|
||||
text: gettext("Please consult octoprint.log for details"),
|
||||
type: "error",
|
||||
hide: false
|
||||
});
|
||||
self._markDone("Could not install plugin, unknown error.");
|
||||
if (data && data.errorThrown === "CONFLICT") {
|
||||
// there's already a plugin being installed
|
||||
self._markDone("There's already another plugin install in progress.");
|
||||
} else {
|
||||
new PNotify({
|
||||
title: gettext("Something went wrong"),
|
||||
text: gettext("Please consult octoprint.log for details"),
|
||||
type: "error",
|
||||
hide: false
|
||||
});
|
||||
self._markDone("Could not install plugin, unknown error.");
|
||||
}
|
||||
self.uploadButton.unbind("click");
|
||||
self.uploadFilename(undefined);
|
||||
}
|
||||
@@ -823,16 +830,23 @@ $(function () {
|
||||
var onSuccess = function (response) {
|
||||
self.installUrl("");
|
||||
},
|
||||
onError = function () {
|
||||
self._markDone(
|
||||
"Could not install plugin, unknown error, please consult octoprint.log for details"
|
||||
);
|
||||
new PNotify({
|
||||
title: gettext("Something went wrong"),
|
||||
text: gettext("Please consult octoprint.log for details"),
|
||||
type: "error",
|
||||
hide: false
|
||||
});
|
||||
onError = function (jqXHR) {
|
||||
if (jqXHR.status === 409) {
|
||||
// there's already a plugin being installed
|
||||
self._markDone(
|
||||
"There's already another plugin install in progress."
|
||||
);
|
||||
} else {
|
||||
self._markDone(
|
||||
"Could not install plugin, unknown error, please consult octoprint.log for details"
|
||||
);
|
||||
new PNotify({
|
||||
title: gettext("Something went wrong"),
|
||||
text: gettext("Please consult octoprint.log for details"),
|
||||
type: "error",
|
||||
hide: false
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (reinstall) {
|
||||
|
||||
Reference in new issue
Block a user