Class: ComplyanceSDK::Jobs::ProcessDocumentJob
- Defined in:
- lib/complyance_sdk/jobs/process_document_job.rb
Overview
Background job for processing documents asynchronously
Instance Method Summary collapse
-
#perform(request_data, callback_url = nil, callback_headers = {}) ⇒ Object
Process a document in the background.
Instance Method Details
#perform(request_data, callback_url = nil, callback_headers = {}) ⇒ Object
Process a document in the background
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/complyance_sdk/jobs/process_document_job.rb', line 14 def perform(request_data, callback_url = nil, callback_headers = {}) log_job("Starting document processing", context: { document_type: request_data["document_type"], country: request_data["country"] }) begin # Process the document response = sdk_client.post("/api/v1/unify", request_data) log_job("Document processed successfully", context: { response_status: response["status"], submission_id: response.dig("data", "submission_id") }) # Send callback if provided if callback_url send_callback(callback_url, callback_headers, { status: "success", data: response, request_id: request_data["metadata"]&.dig("request_id") }) end response rescue => error log_job("Document processing failed", level: :error, context: { error_class: error.class.name, error_message: error. }) # Send error callback if provided if callback_url send_callback(callback_url, callback_headers, { status: "error", error: { code: error.respond_to?(:code) ? error.code : "unknown_error", message: error. }, request_id: request_data["metadata"]&.dig("request_id") }) end raise error end end |