getJobs is unable to return completed jobs
It seems getJobs is not able to able to return completed jobs no matter what I set "which_jobs" to.
I'm using this documentation: http://nagyak.eastron.hu/doc/system-config-printer-libs-1.2.4/pycups-1.9.51/html/
getJobs accept three values for which_jobs: 'completed', 'not-completed', 'all' 'not-completed', 'all' both only returns not-completed jobs. 'completed' returns nothing.
If I use getJobAttributes on a known completed job ID it works as expected and I can get information about the job.
I am using a fresh install of Cups 2.2.7 and latest pycups (2020-04-08) on SuSe SLES 15sp1.
Hi @TheLure ,
does 'lpstat -W completed' return anything? pycups is just python module above CUPS, using its API to do the stuff - so if CUPS does not return anything, so it is correct in pycups. IMO it can be due the default settings to do not save successfully printed jobs - see PreserveJobFiles/PreserveJobHistory.
Thanks for the reply @zdohnal,
Yes, lpstat -W completed returns completed job according to my PreserveJobFiles setting (set to 2w). PreserveJobHistory is unset so from the docs it should default to "Yes" and be the same value as PreserveJobFiles.
I worked around the issue by storing the Job IDs of all job as they are created outside of cups so I can use getJobAttributes when needed at a later time.
@TheLure would you mind telling me if you are connecting to local CUPS or remote? I connected to the local in my test and it works:
12>>>python
Python 3.7.6 (default, Jan 30 2020, 09:44:41)
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cups
>>> c = cups.Connection()
>>> c.getJobs(0
...
KeyboardInterrupt
>>> c.getJobs()
{}
>>> c
<cups.Connection object for /var/run/cups/cups.sock at 0x7f2c40c24510>
>>> c.getJobs(which_jobs='completed')
{597: {'job-uri': 'ipp://localhost/jobs/597'}, 596: {'job-uri': 'ipp://localhost/jobs/596'}, 595: {'job-uri': 'ipp://localhost/jobs/595'}, 594: {'job-uri': 'ipp://localhost/jobs/594'}, 593: {'job-uri': 'ipp://localhost/jobs/593'}, 592: {'job-uri': 'ipp://localhost/jobs/592'}, 590: {'job-uri': 'ipp://localhost/jobs/590'}, 589: {'job-uri': 'ipp://localhost/jobs/589'}, 588: {'job-uri': 'ipp://localhost/jobs/588'}}
>>>
(done in Fedora 31)
@zdohnal I am connecting to localhost. I ran getJobs again the same way you did above and notice a strange thing comparing result from lpstat -W completed and c.getJobs(which_jobs='completed'). Using c.getJobs(which_jobs='completed') I got 9 jobs compared to 57 from lpstat (my host and cups installation are fresh installed). What I also noticed is that the jobs returned by getJobs was NOT returned by lpstat. They are different jobs. Comparing to the full log in cups web interface it seems that on my installation c.getJobs(which_jobs='completed') does in fact return all 'cancelled' jobs instead. Could there be some constants for jobs status values mixed up or something like that?
# lpstat -W completed
IPP_cups_test-73 root 104448 Thu Apr 16 11:36:04 2020
test-66 root 104448 Wed Apr 15 14:58:09 2020
test-65 root 268288 Wed Apr 15 14:54:13 2020
TestClass02-64 root 268288 Wed Apr 15 14:50:45 2020
TestClass02-63 root 269312 Wed Apr 15 14:50:42 2020
TestClass01-62 root 96256 Wed Apr 15 14:50:39 2020
TestClass02-61 root 268288 Wed Apr 15 09:49:36 2020
TestClass02-60 root 269312 Wed Apr 15 09:49:34 2020
TestClass01-59 root 96256 Wed Apr 15 09:49:31 2020
TestClass02-58 root 268288 Tue Apr 14 13:41:53 2020
TestClass02-57 root 269312 Tue Apr 14 13:41:51 2020
TestClass01-56 root 96256 Tue Apr 14 13:41:48 2020
TestClass02-55 root 268288 Tue Apr 14 11:52:42 2020
TestClass02-54 root 269312 Tue Apr 14 11:52:40 2020
TestClass01-53 root 96256 Tue Apr 14 11:52:37 2020
TestClass02-49 root 268288 Thu Apr 9 15:54:17 2020
TestClass02-48 root 269312 Thu Apr 9 15:54:15 2020
TestClass01-47 root 96256 Thu Apr 9 15:54:12 2020
TestClass02-46 root 268288 Thu Apr 9 15:39:57 2020
TestClass02-45 root 269312 Thu Apr 9 15:39:55 2020
TestClass01-44 root 96256 Thu Apr 9 15:39:52 2020
TestClass02-43 root 268288 Thu Apr 9 15:38:48 2020
TestClass02-42 root 269312 Thu Apr 9 15:38:46 2020
TestClass01-41 root 96256 Thu Apr 9 15:38:43 2020
TestClass02-40 root 268288 Wed Apr 8 21:15:19 2020
TestClass02-39 root 269312 Wed Apr 8 21:15:17 2020
TestClass01-38 root 96256 Wed Apr 8 21:15:14 2020
TestClass02-37 root 268288 Wed Apr 8 21:14:13 2020
TestClass02-36 root 269312 Wed Apr 8 21:14:11 2020
TestClass01-35 root 96256 Wed Apr 8 21:14:08 2020
TestClass02-34 root 268288 Wed Apr 8 20:55:49 2020
TestClass02-33 root 269312 Wed Apr 8 20:55:47 2020
TestClass01-32 root 96256 Wed Apr 8 20:55:44 2020
TestClass02-31 root 268288 Wed Apr 8 19:40:09 2020
TestClass02-30 root 269312 Wed Apr 8 19:40:06 2020
TestClass02-29 root 268288 Wed Apr 8 19:36:12 2020
TestClass02-28 root 269312 Wed Apr 8 19:36:09 2020
TestClass02-27 root 268288 Wed Apr 8 19:22:38 2020
TestClass02-26 root 269312 Wed Apr 8 19:22:35 2020
TestClass01-25 root 96256 Wed Apr 8 19:22:33 2020
TestClass01-24 root 96256 Wed Apr 8 19:21:58 2020
TestClass01-23 root 0 Wed Apr 8 19:20:12 2020
TestClass01-22 root 97280 Wed Apr 8 19:19:09 2020
TestClass01-21 root 97280 Wed Apr 8 15:23:03 2020
TestClass01-20 root 97280 Wed Apr 8 15:22:06 2020
TestClass01-19 root 97280 Wed Apr 8 15:13:01 2020
TestClass01-18 root 97280 Wed Apr 8 15:12:58 2020
TestClass01-17 root 97280 Wed Apr 8 15:12:56 2020
TestClass01-16 root 97280 Wed Apr 8 14:38:38 2020
TestClass01-15 root 97280 Wed Apr 8 14:38:18 2020
TestClass01-14 root 97280 Wed Apr 8 14:36:40 2020
TestClass01-13 root 97280 Wed Apr 8 13:30:46 2020
TestClass01-12 root 97280 Wed Apr 8 13:14:58 2020
TestClass01-11 root 97280 Wed Apr 8 13:12:43 2020
TestClass01-10 root 97280 Wed Apr 8 13:11:31 2020
TestClass01-9 root 97280 Wed Apr 8 13:09:49 2020
TestClass01-8 root 97280 Wed Apr 8 13:01:45 2020
# python3
Python 3.6.10 (default, Dec 19 2019, 15:48:40) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cups
>>> c = cups.Connection()
>>> c.getJobs()
{}
>>> c.getJobs(which_jobs='completed')
{73: {'job-uri': 'ipp://localhost/jobs/73'}, 69: {'job-uri': 'ipp://localhost/jobs/69'}, 67: {'job-uri': 'ipp://localhost/jobs/67'}, 68: {'job-uri': 'ipp://localhost/jobs/68'}, 66: {'job-uri': 'ipp://localhost/jobs/66'}, 65: {'job-uri': 'ipp://localhost/jobs/65'}, 50: {'job-uri': 'ipp://localhost/jobs/50'}, 1: {'job-uri': 'ipp://localhost/jobs/1'}, 2: {'job-uri': 'ipp://localhost/jobs/2'}}
>>> c.getJobs(which_jobs='all')
{1: {'job-uri': 'ipp://localhost/jobs/1'}, 2: {'job-uri': 'ipp://localhost/jobs/2'}, 50: {'job-uri': 'ipp://localhost/jobs/50'}, 65: {'job-uri': 'ipp://localhost/jobs/65'}, 66: {'job-uri': 'ipp://localhost/jobs/66'}, 67: {'job-uri': 'ipp://localhost/jobs/67'}, 68: {'job-uri': 'ipp://localhost/jobs/68'}, 69: {'job-uri': 'ipp://localhost/jobs/69'}, 73: {'job-uri': 'ipp://localhost/jobs/73'}}
@TheLure Strange... I'll try to create some cancelled jobs too and check it later.
Otherwise if I will not be able to reproduce, please contact SuSe support about it too.
I'm not sure how to address the SuSe ticket as I can only reproduce the behaviour via pycups, I'm sure they will just say it's a pycups problem. The cups core tools seems to report correctly. If you can verify the problem is inside cups however I will create a ticket for sure. As I worked around the problem I will not be doing more testing unless requested. I need to move forward with our project.
I will try to revisit this issue in a few weeks and see if I can get the same behavior just using cups tools so I can contact SuSe.
Edit: Oh, suse DO supply pycups in a official repo for Sles 15. :) I will submit a ticket.
I can confirm it's a bug in centos/rhel 7, however it worked well in el6. The issue is that it failed to get a valid job_id. Even though it is fixed, it still has some other issue that failed to get some attributes.
https://github.com/OpenPrinting/pycups/issues/22 is closed and related to this issue.
https://github.com/caot/pycups/blob/1.9.74-el7/cupsconnection.c fixed the issue to get a valid job_id, however it still has some other issue that failed to get some attributes such as that mentioned at https://github.com/OpenPrinting/pycups/issues/10