<commit_before>require 'combine_pdf'
require 'net/http'

class RunPdfCombinerWorker
  include Sidekiq::Worker
  include PaasS3

  sidekiq_options retry: 2

  def perform
    @dir = ENV["AWS_PDF_ROOT_PATH"] || ''
    @key = ENV["AWS_PDF_FILENAME"] || 'tariff.pdf'
    initialize_s3(s3_file_path)
    setup_ephemeral_directory
    create_combined_pdf
    upload_to_s3
    verify_on_s3
    delete_from_ephemeral
    email_results
  end

  private

  def setup_ephemeral_directory
    dir = File.join(Rails.root, "public", "pdf", "tariff")
    return if File.exist?(dir)

    FileUtils.mkpath(dir)
  end

  def create_combined_pdf
    pdf = CombinePDF.new
    @chapters = bucket.objects(prefix: bucket_prefix).collect(&:key)<commit_msg>Update filename of combined PDF with date it was produced<commit_after>require 'combine_pdf'
require 'net/http'

class RunPdfCombinerWorker
  include Sidekiq::Worker
  include PaasS3

  sidekiq_options retry: 2

  def perform
    @dir = ENV["AWS_PDF_ROOT_PATH"] || ''
    @key = ENV["AWS_PDF_FILENAME"] || "UK-Trade-Tariff-#{Date.today.strftime('%d-%m-%Y')}.pdf"
    initialize_s3(s3_file_path)
    setup_ephemeral_directory
    create_combined_pdf
    upload_to_s3
    verify_on_s3
    delete_from_ephemeral
    email_results
  end

  private

  def setup_ephemeral_directory
    dir = File.join(Rails.root, "public", "pdf", "tariff")
    return if File.exist?(dir)

    FileUtils.mkpath(dir)
  end

  def create_combined_pdf
    pdf = CombinePDF.new
    @chapters = bucket.objects(prefix: bucket_prefix).collect(&:key)
{'fraction_non_alphanumeric': 0.09858247422680412, 'fraction_numerical': 0.007731958762886598, 'mean_word_length': 4.058631921824104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1442635', 'n_tokens_mistral': 584, 'n_tokens_neox': 562, 'n_words': 104}