@@ -18,22 +18,7 @@ def initialize(api_key: '')
1818 @mindee_api = Mindee ::V2 ::HTTP ::MindeeApiV2 . new ( api_key : api_key )
1919 end
2020
21- # Retrieves a result from a given queue or URL to the result.
22- # @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
23- # @param resource [String] ID of the inference or URL to the result.
24- # @return [Mindee::V2::Parsing::BaseResponse]
25- def get_result ( product , resource )
26- @mindee_api . req_get_result ( product , resource )
27- end
28-
29- # Retrieves an inference from a given queue or URL to the job.
30- # @param job_id [String] ID of the job.
31- # @return [Mindee::V2::Parsing::JobResponse]
32- def get_job ( job_id )
33- @mindee_api . req_get_job ( job_id )
34- end
35-
36- # Enqueue a document for async parsing.
21+ # Send a file to the asynchronous processing queue for inference.
3722 # @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
3823 # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
3924 # The source of the input document (local file or URL).
@@ -51,16 +36,48 @@ def enqueue(
5136 @mindee_api . req_post_product_enqueue ( input_source , normalized_params )
5237 end
5338
54- # Enqueues to an asynchronous endpoint and automatically polls for a response.
55- #
39+ # Get the status of an inference that was previously enqueued.
40+ # Can be used for polling.
41+ # @param url [String] HTTPS URL to the job.
42+ # @return [Mindee::V2::Parsing::JobResponse]
43+ def get_job_by_url ( url )
44+ @mindee_api . req_get_job_by_url ( url )
45+ end
46+
47+ # Get the result of an inference that was previously enqueued.
48+ # @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
49+ # @param url [String] HTTPS URL to the result.
50+ # @return [Mindee::V2::Parsing::BaseResponse]
51+ def get_result_by_url ( product , url )
52+ @mindee_api . req_get_result_by_url ( product , url )
53+ end
54+
55+ # Get the result of an inference that was previously enqueued.
56+ # Prefer using `get_result_by_url` using the result URL returned by the Job.
57+ # @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
58+ # @param resource [String] ID of the inference or URL to the result.
59+ # @return [Mindee::V2::Parsing::BaseResponse]
60+ def get_result ( product , resource )
61+ @mindee_api . req_get_result_by_id ( product , resource )
62+ end
63+
64+ # Get the status of an inference that was previously enqueued.
65+ # Prefer using `get_job_by_url` with the polling URL returned by enqueue.
66+ # @param job_id [String] ID of the job.
67+ # @return [Mindee::V2::Parsing::JobResponse]
68+ def get_job ( job_id )
69+ @mindee_api . req_get_job_by_id ( job_id )
70+ end
71+
72+ # Send a file to the inference queue and return the results when complete.
5673 # @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
5774 # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
5875 # The source of the input document (local file or URL).
5976 # @param params [Hash, ClientOptions::BaseProductParameters] Parameters for the inference.
6077 # @param polling_options [Hash, PollingOptions, nil] Parameters for polling.
6178 # @param cancellation_token [Mindee::HTTP::CancellationToken, nil] Token for cancellation.
6279 # @return [Parsing::BaseResponse]
63- # rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
80+ # rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
6481 def enqueue_and_get_result (
6582 product ,
6683 input_source ,
@@ -84,29 +101,31 @@ def enqueue_and_get_result(
84101
85102 sleep ( normalized_params . polling_options . initial_delay_sec )
86103 retry_counter = 1
87- poll_results = get_job ( job_id )
104+ polling_url = enqueue_response . job . polling_url
105+
106+ job_response = get_job_by_url ( polling_url )
88107
89108 while retry_counter < normalized_params . polling_options . max_retries
90- if poll_results . job . status == 'Failed'
109+ if job_response . job . status == 'Failed'
91110 break
92- elsif !poll_results . job . result_url . nil?
93- return get_result ( product , poll_results . job . result_url )
111+ elsif !job_response . job . result_url . nil?
112+ return get_result_by_url ( product , job_response . job . result_url )
94113 end
95114
96115 logger . debug (
97116 "Successfully enqueued inference with job id: #{ job_id } .\n " \
98117 "Attempt n°#{ retry_counter } /#{ normalized_params . polling_options . max_retries } .\n " \
99- "Job status: #{ poll_results . job . status } ."
118+ "Job status: #{ job_response . job . status } ."
100119 )
101120
102121 raise Mindee ::Error ::MindeeError , 'Enqueueing of the document was canceled.' if cancellation_token &.canceled?
103122
104123 sleep ( normalized_params . polling_options . delay_sec )
105- poll_results = get_job ( job_id )
124+ job_response = get_job_by_url ( polling_url )
106125 retry_counter += 1
107126 end
108127
109- error = poll_results . job . error
128+ error = job_response . job . error
110129 unless error . nil?
111130 err_to_raise = Mindee ::Error ::MindeeHTTPErrorV2 . new ( error )
112131 # NOTE: purposefully decoupled from the line above, otherwise rubocop thinks `error` is a `message` param.
0 commit comments