OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
1k stars 178 forks source link

How to get a list of canceled or successful print jobs? #828

Closed JoRe2000 closed 9 months ago

JoRe2000 commented 9 months ago

I want to save successful printed jobs to an external database. Therefore I am currently using the lpstat -w completed shell command and save the output to that database. But unfortunately the command also returns canceld print jobs. So is there any possibility to get a list without the canceled print jobs?

zdohnal commented 9 months ago

IMO it is a bug - IIUC enum values in cups/ipp.h, 'completed' is for successfully completed jobs, but the scheduler adds canceled and aborted jobs into the list. However, the behavior can be expected by users, so I'll try to introduce a new value for this in the attached PR.

michaelrsweet commented 9 months ago

@zdohnal It is not a bug.

In IPP, getting a list of 'completed' jobs means any job in a terminating state (aborted, canceled, or completed). Getting a list of 'not-completed' jobs means any job in the pending, pending-held, processing, or processing-stopped states.

There are extensions to only list jobs in the aborted or canceled states but not one that only lists jobs in the completed state.

zdohnal commented 9 months ago

@michaelrsweet Aha, I was mistaken by the comment for IPP_JSTATE_COMPLETED, so I incorrectly assumed job state value and which-jobs value can express the similar thing - but later I looked into RFC 2911 and found exactly the same definition as you mentioned :) . To be honest, I would expect 'which-jobs' would support 'all', "finished" (now 'completed'), "not-finished" (now 'not-completed') and then every job status one by one. Having a job state with the same name as which-jobs value, but giving a different set of jobs is confusing - however even if a change got into IPP standard, there will be many devices in the wilderness with old firmware, where this won't work... @michaelrsweet does it sound better to implement this only on 'lpstat' level, where it would accept a new parameter value, but asked for 'which-jobs=completed' via Get-Jobs, and the filtering would happen in lpstat?

michaelrsweet commented 9 months ago

@zdohnal Implementing this in lpstat is a possibility, however remember that "lpstat -W completed" has returned jobs in the canceled, aborted, or completed states since CUPS 1.0... Perhaps a new option (--state completed) could filter things more cleanly?

Also, for the original reporter you can use ipptool to get a list of jobs in different formats, including the job-state value that you could filter on, for example:

ipptool ipp://localhost/ get-completed-jobs.test
ipptool ipp://localhost/printers/PRINTERNAME get-completed-jobs.test

You can make your own test file to display specific attributes/values, and depending on the version of CUPS you are running you can get plain text, comma-separated values (-c option for CSV output), JSON values (-j), or XML/plist output (-X).

JoRe2000 commented 9 months ago

@michaelrsweet Thank you for the answer. The ipptool delivers exactly what I was searching for.