@@ -5,20 +5,27 @@ class APIRemediationJob < ApplicationJob
55
66 def perform ( job_uuid , output_polling_timeout : OUTPUT_POLLING_TIMEOUT )
77 job = PdfJob . find_by! ( uuid : job_uuid )
8+ tempfile = nil
89 tempfile = Down . download ( job . source_url )
910 original_filename = tempfile &.original_filename
1011 job . update! ( output_object_key : original_filename )
12+
13+ page_count = PDF ::Reader . new ( tempfile . path ) . page_count
14+ PageCountQuotaValidator . validate! ( owner : job . owner , page_count : page_count )
15+ job . update! ( page_count : page_count )
16+
1117 safe_original_filename = original_filename . gsub ( /[^A-Za-z0-9.\- _ ]/ , '' )
1218 object_key = "#{ SecureRandom . hex ( 8 ) } _#{ safe_original_filename } "
1319 file_path = tempfile &.path
1420 s3_handler = S3Handler . new ( object_key )
1521 s3_handler . upload_to_input ( file_path )
1622 poll_and_update ( job_uuid , s3_handler , output_polling_timeout )
17- rescue S3Handler ::Error => e
18- update_with_failure ( job , "Failed to upload file to remediation input location: #{ e . message } " )
19- rescue Down ::Error => e
23+ rescue Down ::Error ,
24+ S3Handler ::Error ,
25+ PDF ::Reader ::MalformedPDFError ,
26+ PageCountQuotaValidator ::Error => e
2027 # We may want to retry the download depending on the more specific nature of the failure.
21- update_with_failure ( job , "Failed to download file from source URL: #{ e . message } " )
28+ update_with_failure ( job , "Failed to process job: #{ e . class } : #{ e . message } " )
2229 ensure
2330 RemediationStatusNotificationJob . perform_later ( job_uuid )
2431 tempfile &.close!
0 commit comments