<commit_before>class CitesReportValidationJob < ApplicationJob
  queue_as :default

  def perform(aru_id, force_submit)
    Rails.logger.info "Started validation of CITES Report #{aru_id}"
    begin
      aru = Trade::AnnualReportUpload.find(aru_id)
    rescue ActiveRecord::RecordNotFound => e
      # catch this exception so that retry is not scheduled
      Rails.logger.warn "CITES Report not found #{aru_id}"
      return
    end
    # TODO:
    Rails.logger.info "Finished validation of CITES Report #{aru_id}"
  end
end<commit_msg>run validation rules in worker<commit_after>class CitesReportValidationJob < ApplicationJob
  queue_as :default

  def perform(aru_id, force_submit)
    Rails.logger.info "Started validation of CITES Report #{aru_id}"
    begin
      aru = Trade::AnnualReportUpload.find(aru_id)
    rescue ActiveRecord::RecordNotFound => e
      # catch this exception so that retry is not scheduled
      Rails.logger.warn "CITES Report not found #{aru_id}"
      return
    end
    result = {}
    aru.process_validation_rules
    if !aru.primary_validation_errors.empty?
      result[:Status] = 'ERROR'
      result[:Message] = 'Primary errors detected in CITES Report'
      # TODO: here we go with errors row by row
    elsif !aru.secondary_validation_errors.empty? && !force_submit
      result[:Status] = 'ERROR'
      result[:Message] = 'Secondary errors detected in CITES Report'
      # TODO: here we go with errors row by row
    else
      result[:Status] = 'SUCCESS'
      # TODO: proceed with submission
    end
    Rails.logger.info result
    Rails.logger.info "Finished validation of CITES Report #{aru_id}"
  end
end
{'fraction_non_alphanumeric': 0.08152173913043478, 'fraction_numerical': 0.0, 'mean_word_length': 3.43048128342246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5549534', 'n_tokens_mistral': 485, 'n_tokens_neox': 472, 'n_words': 151}