diff --git a/printer/modules/gerard.py b/printer/modules/gerard.py index cde3d463..9d247df0 100644 --- a/printer/modules/gerard.py +++ b/printer/modules/gerard.py @@ -44,7 +44,6 @@ def create_print_job( printer_name, file_path, is_development_mode=False, - # no_dev_printer=False ): hold_time = "immediate" if is_development_mode: diff --git a/printer/modules/lpstat_helpers.py b/printer/modules/lpstat_helpers.py index 019354f5..64258ef4 100644 --- a/printer/modules/lpstat_helpers.py +++ b/printer/modules/lpstat_helpers.py @@ -4,10 +4,9 @@ from modules import sqlite_helpers -LPSTAT_CMD = "lpstat -o HP_LaserJet_p2015dn_Right" -SLEEP_TIME = 2 -jobs_seen_last = set() +LPSTAT_CMD = "lpstat -o -W completed HP_LaserJet_p2015dn_Right" +POLL_LPSTAT_INTERVAL_SECONDS = 2 logging.basicConfig( # in mondo we trust @@ -18,8 +17,14 @@ def query_lpstat(): - global jobs_seen_last global current_jobs + """ + the output of this command looks like + ben@ben:/app# lpstat -W completed -o HP_LaserJet_p2015dn_Right + HP_LaserJet_p2015dn_Right-3 ben 5120 Mon Dec 22 21:43:54 2025 + HP_LaserJet_p2015dn_Right-2 ben 8192 Mon Dec 22 21:43:23 2025 + HP_LaserJet_p2015dn_Right-1 ben 8192 Mon Dec 22 21:41:08 2025 + """ p = subprocess.Popen( LPSTAT_CMD, shell=True, @@ -52,22 +57,13 @@ def query_lpstat(): def poll_lpstat(sqlite_file): - global jobs_seen_last while True: try: - current_jobs = set(query_lpstat()) - completed_jobs = jobs_seen_last - current_jobs - + completed_jobs = set(query_lpstat()) sqlite_helpers.mark_jobs_completed( sqlite_file, [job for job in completed_jobs] ) - sqlite_helpers.mark_jobs_acknowledged( - sqlite_file, [job for job in current_jobs] - ) - - jobs_seen_last.clear() - jobs_seen_last.update(current_jobs) except Exception: logging.exception("what happened to query_lpstat?") - time.sleep(SLEEP_TIME) + time.sleep(POLL_LPSTAT_INTERVAL_SECONDS) diff --git a/printer/modules/sqlite_helpers.py b/printer/modules/sqlite_helpers.py index 82d4244a..2da816df 100644 --- a/printer/modules/sqlite_helpers.py +++ b/printer/modules/sqlite_helpers.py @@ -56,7 +56,7 @@ def mark_jobs_with_status(sqlite_file, jobs, status): job_ids = [(job_id,) for job_id in jobs] if not job_ids: return - logging.info(f"marking {job_ids} as {status} in sqlite") + logging.debug(f"marking {job_ids} as {status} in sqlite") sql_update = ( f"UPDATE logs SET status = '{status}' WHERE job_id = ?" diff --git a/printer/test/test_lpstat.py b/printer/test/test_lpstat.py index 6a58e580..a36c76ac 100644 --- a/printer/test/test_lpstat.py +++ b/printer/test/test_lpstat.py @@ -20,9 +20,6 @@ class TestLpStatSqlite(unittest.TestCase): "HP_LaserJet_p2015dn_Right-53 root 5120 Sat May 31 18:19:38 2025" ) - def setUp(self): - lpstat_helpers.jobs_seen_last.clear() - # returns a single line result @mock.patch("modules.lpstat_helpers.subprocess.Popen") def test_query_lpstat(self, mock_popen): @@ -77,9 +74,6 @@ def test_query_lpstat_nonzero(self, mock_popen): def test_poll_lpstat( self, mock_sleep, mock_query_lpstat, mock_mark_acknowledged, mock_mark_completed ): - # Set initial seen job - lpstat_helpers.jobs_seen_last = {"HP_LaserJet_p2015dn_Right-52"} - # Simulate current jobs reported by lpstat mock_query_lpstat.return_value = [ "HP_LaserJet_p2015dn_Right-53", @@ -94,20 +88,7 @@ def test_poll_lpstat( # Check correct jobs marked as completed and acknowledged mock_mark_completed.assert_called_once_with( - "dummy.db", ["HP_LaserJet_p2015dn_Right-52"] - ) - mock_mark_acknowledged.assert_called_once() - database_name, acknowledged_jobs = mock_mark_acknowledged.call_args_list[0].args - self.assertEqual(database_name, "dummy.db") - self.assertCountEqual( - acknowledged_jobs, - ["HP_LaserJet_p2015dn_Right-53", "HP_LaserJet_p2015dn_Right-54"], - ) - - # Ensure state was cleared and updated - self.assertEqual( - lpstat_helpers.jobs_seen_last, - {"HP_LaserJet_p2015dn_Right-53", "HP_LaserJet_p2015dn_Right-54"}, + "dummy.db", ["HP_LaserJet_p2015dn_Right-54", "HP_LaserJet_p2015dn_Right-53"], )