🐛 Fix sending of cancel, pause, resume scripts
This commit is contained in:
1 parent
864ac12097
commit
e441976682
2 files changed
+44
-84
No files matched your search
@@ -362,7 +362,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
"continuing without it".format(self.timeouts.get("position_log_wait", 10.0)))
|
||||
self._cancel_preparation_done()
|
||||
|
||||
def _cancel_preparation_done(self, check_timer=True, user=None):
|
||||
def _cancel_preparation_done(self, check_timer=True, suppress_script=False, user=None):
|
||||
if user is None:
|
||||
with self._action_users_mutex:
|
||||
try:
|
||||
@@ -378,11 +378,13 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
return
|
||||
|
||||
# TODO: recovery data
|
||||
self.notify_listeners("on_protocol_job_cancelled", self, self._job,
|
||||
position=self.cancel_position.as_dict(),
|
||||
suppress_script=suppress_script,
|
||||
user=user)
|
||||
|
||||
def finalize():
|
||||
self.state = ProtocolState.CONNECTED
|
||||
self.notify_listeners("on_protocol_job_cancelled", self, self._job, user=user)
|
||||
|
||||
self.send_commands(SendQueueMarker(finalize))
|
||||
self._continue_sending()
|
||||
|
||||
@@ -426,7 +428,8 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
"trigger:record_position"})
|
||||
self._continue_sending()
|
||||
else:
|
||||
self._cancel_preparation_done(check_timer=False, user=user)
|
||||
self._cancel_preparation_done(check_timer=False,
|
||||
user=user)
|
||||
|
||||
# pause handling
|
||||
|
||||
@@ -451,7 +454,10 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
elif check_timer:
|
||||
return
|
||||
|
||||
self.notify_listeners("on_protocol_job_paused", self, self._job, user=user, suppress_script=suppress_script)
|
||||
self.notify_listeners("on_protocol_job_paused", self, self._job,
|
||||
position=self.pause_position.as_dict(),
|
||||
suppress_script=suppress_script,
|
||||
user=user)
|
||||
|
||||
# wait for current commands to be sent, then switch to paused state
|
||||
def finalize():
|
||||
@@ -502,7 +508,9 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
"trigger:record_position"})
|
||||
self._continue_sending()
|
||||
else:
|
||||
self._pause_preparation_done(check_timer=False, suppress_script=suppress_scripts_and_commands)
|
||||
self._pause_preparation_done(check_timer=False,
|
||||
suppress_script=suppress_scripts_and_commands,
|
||||
user=user)
|
||||
|
||||
def resume_processing(self, user=None, tags=None, only_adjust_state=False):
|
||||
if only_adjust_state:
|
||||
@@ -622,15 +630,17 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
|
||||
if self.state in ProtocolState.PROCESSING_STATES and not self._job.parallel and not self.job_on_hold and not force:
|
||||
if len(commands) > 1:
|
||||
command_type = None
|
||||
|
||||
result = False
|
||||
for command in commands:
|
||||
try:
|
||||
self._command_queue.put((sanitize_command(command, command_type, tags), on_sent), item_type=command_type)
|
||||
return True
|
||||
result = True
|
||||
except TypeAlreadyInQueue as e:
|
||||
self._logger.debug("Type already in queue: " + e.type)
|
||||
return False
|
||||
return result
|
||||
elif self._is_operational() or force:
|
||||
self._send_commands(*commands, on_sent=on_sent, command_type=command_type, tags=tags)
|
||||
return self._send_commands(*commands, on_sent=on_sent, command_type=command_type, tags=tags)
|
||||
|
||||
def send_script(self, script, context=None, *args, **kwargs):
|
||||
if context is None:
|
||||
|
||||
@@ -646,25 +646,6 @@ class Printer(PrinterInterface,
|
||||
if self._protocol is None or not self._protocol.state in (ProtocolState.PROCESSING, ProtocolState.PAUSED):
|
||||
return
|
||||
|
||||
# reset progress, height, print time
|
||||
self._set_current_z(None)
|
||||
self._reset_progress_data()
|
||||
|
||||
# mark print as failure
|
||||
if self._job is not None:
|
||||
origin = self._get_origin_for_job(self._job.job)
|
||||
self._file_manager.log_print(origin,
|
||||
self._job.job.name,
|
||||
time.time(),
|
||||
self._job.job.elapsed,
|
||||
False,
|
||||
self._printer_profile_manager.get_current_or_default()["id"])
|
||||
payload = {
|
||||
"file": self._job.job.name,
|
||||
"origin": origin
|
||||
}
|
||||
eventManager().fire(Events.PRINT_FAILED, payload)
|
||||
|
||||
self._protocol.cancel_processing(error=error,
|
||||
user=user,
|
||||
tags=kwargs.get("tags", set()) | {"trigger:printer.cancel_print"})
|
||||
@@ -1398,25 +1379,14 @@ class Printer(PrinterInterface,
|
||||
return
|
||||
|
||||
firmware_error = kwargs.get("error", None)
|
||||
cancel_position = kwargs.get("position", None)
|
||||
suppress_scripts = kwargs.get("suppress_scripts", None)
|
||||
|
||||
payload = job.event_payload()
|
||||
if payload:
|
||||
payload["user"] = kwargs.get("user")
|
||||
if firmware_error:
|
||||
payload["firmwareError"] = firmware_error
|
||||
if cancel_position:
|
||||
payload["position"] = cancel_position
|
||||
eventManager().fire(Events.PRINT_CANCELLING, payload)
|
||||
|
||||
# TODO: Should this be in on_protocol_cancelled?
|
||||
if not suppress_scripts:
|
||||
self.script("afterPrintCancelled",
|
||||
context=dict(event=payload),
|
||||
part_of_job=True,
|
||||
must_be_set=False)
|
||||
|
||||
def on_protocol_job_cancelled(self, protocol, job, *args, **kwargs):
|
||||
if protocol != self._protocol:
|
||||
return
|
||||
@@ -1430,6 +1400,7 @@ class Printer(PrinterInterface,
|
||||
self._update_progress_data()
|
||||
|
||||
cancel_position = kwargs.get("position", None)
|
||||
suppress_script = kwargs.get("suppress_script", None)
|
||||
|
||||
payload = job.event_payload(incl_last=True)
|
||||
if payload:
|
||||
@@ -1437,6 +1408,12 @@ class Printer(PrinterInterface,
|
||||
if cancel_position:
|
||||
payload["position"] = cancel_position
|
||||
|
||||
if not suppress_script:
|
||||
self.script("afterPrintCancelled",
|
||||
context=dict(event=payload),
|
||||
part_of_job=True,
|
||||
must_be_set=False)
|
||||
|
||||
eventManager().fire(Events.PRINT_CANCELLED, payload)
|
||||
self._logger_job.info("Print job cancelled - origin: {}, path: {}, owner: {}, user: {}".format(payload.get("origin"),
|
||||
payload.get("path"),
|
||||
@@ -1453,37 +1430,12 @@ class Printer(PrinterInterface,
|
||||
payload["time"],
|
||||
False,
|
||||
self._printer_profile_manager.get_current_or_default()["id"])
|
||||
eventManager().fire(Events.PRINT_FAILED, payload)
|
||||
eventManager().fire(Events.PRINT_FAILED, payload)
|
||||
|
||||
thread = threading.Thread(target=finalize)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
def on_protocol_job_pausing(self, protocol, job, *args, **kwargs):
|
||||
if protocol != self._protocol:
|
||||
return
|
||||
|
||||
if self._job is None or job != self._job.job:
|
||||
return
|
||||
|
||||
if self._job_event_handled(protocol, job, "pausing"):
|
||||
return
|
||||
|
||||
pause_position = kwargs.get("position", None)
|
||||
suppress_scripts = kwargs.get("suppress_scripts", None)
|
||||
|
||||
payload = job.event_payload()
|
||||
if payload:
|
||||
payload["user"] = kwargs.get("user")
|
||||
if pause_position:
|
||||
payload["position"] = pause_position
|
||||
# TODO: Should this be in on_protocol_paused?
|
||||
if not suppress_scripts:
|
||||
self.script("afterPrintPaused",
|
||||
context=dict(event=payload),
|
||||
part_of_job=True,
|
||||
must_be_set=False)
|
||||
|
||||
def on_protocol_job_paused(self, protocol, job, *args, **kwargs):
|
||||
if protocol != self._protocol:
|
||||
return
|
||||
@@ -1495,37 +1447,27 @@ class Printer(PrinterInterface,
|
||||
return
|
||||
|
||||
pause_position = kwargs.get("position", None)
|
||||
suppress_script = kwargs.get("suppress_script", None)
|
||||
|
||||
payload = job.event_payload()
|
||||
if payload:
|
||||
payload["user"] = kwargs.get("user")
|
||||
if pause_position:
|
||||
payload["position"] = pause_position
|
||||
|
||||
if not suppress_script:
|
||||
self.script("afterPrintPaused",
|
||||
context=dict(event=payload),
|
||||
part_of_job=True,
|
||||
must_be_set=False)
|
||||
|
||||
eventManager().fire(Events.PRINT_PAUSED, payload)
|
||||
|
||||
self._logger_job.info("Print job paused - origin: {}, path: {}, owner: {}, user: {}".format(payload.get("origin"),
|
||||
payload.get("path"),
|
||||
payload.get("owner"),
|
||||
payload.get("user")))
|
||||
|
||||
def on_protocol_job_resuming(self, protocol, job, *args, **kwargs):
|
||||
if protocol != self._protocol:
|
||||
return
|
||||
|
||||
if self._job is None or job != self._job.job:
|
||||
return
|
||||
|
||||
if self._job_event_handled(protocol, job, "resuming"):
|
||||
return
|
||||
|
||||
suppress_scripts = kwargs.get("suppress_scripts", False)
|
||||
|
||||
payload = job.event_payload()
|
||||
if payload and not suppress_scripts:
|
||||
# TODO: Should this be in on_protocol_resumed?
|
||||
self.script("beforePrintResumed",
|
||||
context=dict(event=payload),
|
||||
must_be_set=False)
|
||||
|
||||
def on_protocol_job_resumed(self, protocol, job, *args, **kwargs):
|
||||
if protocol != self._protocol:
|
||||
return
|
||||
@@ -1536,9 +1478,17 @@ class Printer(PrinterInterface,
|
||||
if self._job_event_handled(protocol, job, "resumed"):
|
||||
return
|
||||
|
||||
suppress_scripts = kwargs.get("suppress_scripts", False)
|
||||
|
||||
payload = job.event_payload()
|
||||
if payload:
|
||||
payload["user"] = kwargs.get("user")
|
||||
|
||||
if not suppress_scripts:
|
||||
self.script("beforePrintResumed",
|
||||
context=dict(event=payload),
|
||||
must_be_set=False)
|
||||
|
||||
eventManager().fire(Events.PRINT_RESUMED, payload)
|
||||
self._logger_job.info("Print job resumed - origin: {}, path: {}, owner: {}, user: {}".format(payload.get("origin"),
|
||||
payload.get("path"),
|
||||
|
||||
Reference in new issue
Block a user