Skip to content

Commit

Permalink
Merge pull request #121 from smartin015/fix_random_failures
Browse files Browse the repository at this point in the history
Fix print successes treated as failures, bump version to 2.1.2
  • Loading branch information
smartin015 authored Sep 10, 2022
2 parents cffd71a + 8f2d88d commit 3cc8306
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
18 changes: 8 additions & 10 deletions continuousprint/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def timeAgo(elapsed):

class Driver:
# If the printer is idle for this long while printing, break out of the printing state (consider it a failure)
PRINTING_IDLE_BREAKOUT_SEC = 10.0
PRINTING_IDLE_BREAKOUT_SEC = 15.0

def __init__(
self,
Expand Down Expand Up @@ -200,7 +200,13 @@ def _state_printing(self, a: Action, p: Printer, elapsed=None):
StatusType.NEEDS_ACTION,
)
return self._state_paused
elif a == Action.SUCCESS:
elif a == Action.SUCCESS or (
p == Printer.IDLE
and time.time() - self.idle_start_ts > self.PRINTING_IDLE_BREAKOUT_SEC
):
# If idle state without event, assume we somehow missed the SUCCESS action.
# We wait for a period of idleness to prevent idle-before-success events
# from double-completing prints.
item = self.q.get_set()

# A limitation of `octoprint.printer`, the "current file" path passed to the driver is only
Expand All @@ -222,14 +228,6 @@ def _state_printing(self, a: Action, p: Printer, elapsed=None):
self._set_status("Waiting for printer to be ready")
elif p == Printer.PAUSED:
return self._state_paused
elif (
p == Printer.IDLE
and time.time() - self.idle_start_ts > self.PRINTING_IDLE_BREAKOUT_SEC
):
# Idle state without event; assume we somehow missed the SUCCESS action
# We wait for a period of idleness to prevent idle-before-success events
# from double-completing prints.
return self._state_failure

def _state_paused(self, a: Action, p: Printer):
self._set_status("Paused", StatusType.NEEDS_ACTION)
Expand Down
4 changes: 2 additions & 2 deletions continuousprint/driver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ def test_idle_while_printing(self):
self.d.action(DA.TICK, DP.IDLE)
self.assertEqual(self.d.state.__name__, self.d._state_printing.__name__)

# Continued idleness triggers failure (retry behavior validated in test_retry_after_failure)
# Continued idleness triggers bed clearing and such
self.d.idle_start_ts = time.time() - (Driver.PRINTING_IDLE_BREAKOUT_SEC + 1)
self.d.action(DA.TICK, DP.IDLE)
self.assertEqual(self.d.state.__name__, self.d._state_failure.__name__)
self.assertEqual(self.d.state.__name__, self.d._state_start_clearing.__name__)

def test_retry_after_failure(self):
self.d.state = self.d._state_failure
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "continuousprint"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "2.1.1"
plugin_version = "2.1.2"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 3cc8306

Please sign in to comment.