https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42596

--- Comment #2 from Kyle M Hall (khall) <[email protected]> ---
Created attachment 199698
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=199698&action=edit
Bug 42596: Add ability for reports APIs ( svc/report, opac/svc/report ) to run
reports as background jobs

Right now, all svc reports act as foreground jobs and return data
immediately. This can cause issues such as apache timeouts for long
running jobs. It would make sense to have the ability for a caller
to ask for a background job and be given an id so that it can a) look
up the status of the job ( waiting, running, finished, failed ) and
if the job is finished, b) download the results of the report.

This patch adds a "run_type" query parameter to svc/report and
opac/svc/report. When run_type is set to background the endpoint
enqueues a background job report and returns a 202 Accepted
with the URL the caller polls for status
With the no run_type ( or a value of "foreground" ) the APIs
behave just as they always have.

Jobs that do not exist return 410 Gone.
Request that contravene the report run type get 422 Unprocessable Entity.
Staff can only poll their own background jobs via this API ( not sure
if this is really needed, but it seemed good to have ).

Example responses against svc/report:

  GET /cgi-bin/koha/svc/report?id=42&run_type=background
  -> 202 Accepted
     Location: /cgi-bin/koha/svc/report?job_id=99
    
{"job_id":99,"status":"new","status_url":"/cgi-bin/koha/svc/report?job_id=99"}

  # Running report
  GET /cgi-bin/koha/svc/report?job_id=99
  -> 200 OK
     {"job_id":99,"status":"started"}

  # Finished report
  GET /cgi-bin/koha/svc/report?job_id=99
  -> 200 OK
    
{"job_id":99,"status":"finished","result_url":"/cgi-bin/koha/svc/report?saved_report_id=42"}

  # Report results
  GET /cgi-bin/koha/svc/report?saved_report_id=42
  -> 200 OK
     [[1,2,3]]

  # Report results with the nice key/value pairs
  GET /cgi-bin/koha/svc/report?saved_report_id=42&annotated=1
  -> 200 OK
     [{"n":1,"m":2,"p":3}]

  # Invalid job id
  GET /cgi-bin/koha/svc/report?job_id=99999
  -> 410 Gone
     {"error":"job_not_found"}

  # Invalid report results retrieval id
  GET /cgi-bin/koha/svc/report?saved_report_id=99999
  -> 410 Gone
     {"error":"saved_report_not_found"}

  # Run type request that is against the report's set run_type
  GET /cgi-bin/koha/svc/report?id=42&run_type=background
  -> 422 Unprocessable Entity
     {"error":"run_type_not_allowed","allowed":"foreground"}

Test Plan:
 1) Apply this patch
 2) Restart all the things!
 3) Create two public SQL reports:
    SELECT 1 AS n, 2 AS m, 3 AS p
    SELECT SLEEP(15) AS done
 4) Browse to svc/report for the first report
    /cgi-bin/koha/svc/report?id=$REPORTID&login_userid=koha&login_password=koha
 5) Note you get the rows array back
 6) Tray again in background mode:
   
/cgi-bin/koha/svc/report?id=$REPORTID&run_type=background&login_userid=koha&login_password=koha
 7) Note the 202 Accepted, with status_url in the JSON body and a matching
Location header
 8) Poll the returned status_url:
   
/cgi-bin/koha/svc/report?job_id=$REPORTID&login_userid=koha&login_password=koha
 9) Note the envelope { job_id, status: 'finished', result_url } with no inline
rows!
10) Get the result_url, the data should look just like a foreground run
   
/cgi-bin/koha/svc/report?saved_report_id=$REPORTID&login_userid=koha&login_password=koha
11) Get the result_url with annotated=1 in the params, it should look like the
foreground version that also as annotated=1
   
/cgi-bin/koha/svc/report?saved_report_id=$REPORTID&login_userid=koha&login_password=koha&annotated=1
12) Enqueue the slow report in background mode, capture the new job id:
    curl
'/cgi-bin/koha/svc/report?id=$SLEEPY_REPORTID&run_type=background&login_userid=koha&login_password=koha'
13) Browse to its' status_url, note status "started" ( unless your jobs queue
is backed up )
14) Wait 16 seconds, reload the url, status should now be "finished"
17) Repeat 4-16 for the OPAC

-- 
You are receiving this mail because:
You are watching all bug changes.
You are the assignee for the bug.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to