Class: BxBuilderChain::DocumentProcessorWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/generators/bx_builder_chain/templates/app/workers/bx_builder_chain/document_processor_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(file_data, llm_class:, client_class:, namespaces:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/generators/bx_builder_chain/templates/app/workers/bx_builder_chain/document_processor_worker.rb', line 9

def perform(file_data, llm_class:, client_class:, namespaces:)
  # Create a new instance of the service class
  service = DocumentUploadService.new(
    files: [file_data],
    user_groups: namespaces,
    client_class_name: client_class,
    llm_class_name: llm_class
  )

  # Use the service method to process the file
  result = service.upload_and_process

  # Log errors if they occur
  if result[:error]
    BxBuilderChain.logger.error("BxBuilderChain::DocumentProcessorWorker Error: #{result[:error]}\n File: #{file_data[:filename]}\nNameSpace: #{namespaces.join(', ')}")
  end

rescue => e
    BxBuilderChain.logger.error("BxBuilderChain::DocumentProcessorWorker Error: #{e.message}\n File: #{file_data[:filename]}\nNameSpace: #{namespaces.join(', ')}")
    # Re-raise the exception to let Sidekiq handle retries
    raise e
end