Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/jobs/process_pdf_job.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
class ProcessPdfJob < ApplicationJob
queue_as :medium_priority

discard_on(RuntimeError) do |job, err|

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Narrow the RuntimeError discard to permanent PDF failures

This treats every bare raise "..." as non-retryable, but PdfImport#process_with_ai and #extract_transactions turn any unsuccessful provider response into exactly that by raising the response message. Since the providers also wrap API/Faraday failures into unsuccessful responses, a transient LLM outage or rate limit is now discarded after one attempt and left failed; use a narrower permanent-error class for bad PDFs/passwords.

Useful? React with 👍 / 👎.

Rails.logger.error("[ProcessPdfJob] Discarded permanently (job_id=#{job.job_id}): #{err.message}")
end

def perform(pdf_import)
return unless pdf_import.is_a?(PdfImport)
return reset_processing_claim(pdf_import) unless pdf_import.pdf_uploaded?
return if pdf_import.status == "complete"
return if pdf_import.status.in?(%w[complete failed])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep queued retries from short-circuiting

When a non-RuntimeError is raised after processing starts, the rescue below updates the import to failed before re-raising. ActiveJob/Sidekiq then deserializes that same PdfImport on the retry, but this new guard returns immediately because the status is already failed, so transient failures such as API/Faraday errors during extraction get only the first attempt instead of the intended queued retries.

Useful? React with 👍 / 👎.

return reset_processing_claim(pdf_import) if pdf_import.ai_processed? && (!pdf_import.statement_with_transactions? || pdf_import.rows_count > 0)

pdf_import.update!(status: :importing)
Expand Down
Loading