<commit_before>class BackupJob < ApplicationJob

  def perform(backup)
    Rails.logger.info("Starting backup for #{backup.service.id}")

    backup_storage_provider = backup.service.backup_storage_provider
    unless backup_storage_provider.present?
      backup.failed!
      return false
    end

    backup.running!
    file_name = backup.service.backup_file_name
    environment_variables = backup.service.backup_environment_variables.merge({
      AWS_ACCESS_TOKEN: backup_storage_provider.environment_variables['AWS_ACCESS_TOKEN'],
      AWS_SECRET_KEY: backup_storage_provider.environment_variables['AWS_SECRET_KEY'],
      AWS_BUCKET_NAME: backup_storage_provider.environment_variables['AWS_BUCKET_NAME'],
      FILE_NAME: file_name
    })

    image = Docker::Image.get('containerdb/backup-restore')
    container = image.run("sh #{backup.service.backup_script_path}", { 'Env' => environment_variables.map {|key, value| "#{key}=#{value}" } })

    response = container.wait(3600)
    Rails.logger.info(container.logs(stderr: true))
    Rails.logger.info(container.logs(stdout: true))

    if response['StatusCode'] == 0
      backup.update(file_name: file_name)
      backup.complete!
    else
      backup.failed!
    end
  rescue
    Rails.logger.info("failed")
    backup.failed!
    raise<commit_msg>Bit cleaner<commit_after>class BackupJob < ApplicationJob

  def perform(backup)
    Rails.logger.info("Starting backup for #{backup.service.id}")

    backup_storage_provider = backup.service.backup_storage_provider
    unless backup_storage_provider.present?
      backup.failed!
      return false
    end

    backup.running!
    file_name = backup.service.backup_file_name
    environment_variables = backup.service.backup_environment_variables.merge({
      AWS_ACCESS_TOKEN: backup_storage_provider.environment_variables['AWS_ACCESS_TOKEN'],
      AWS_SECRET_KEY: backup_storage_provider.environment_variables['AWS_SECRET_KEY'],
      AWS_BUCKET_NAME: backup_storage_provider.environment_variables['AWS_BUCKET_NAME'],
      FILE_NAME: file_name
    })

    image = Docker::Image.get('containerdb/backup-restore')
    container = image.run("sh #{backup.service.backup_script_path}", {
      'Env' => environment_variables.map {|key, value| "#{key}=#{value}" }
    })

    response = container.wait(3600)
    Rails.logger.info(container.logs(stderr: true))
    Rails.logger.info(container.logs(stdout: true))

    if response['StatusCode'] == 0
      backup.update(file_name: file_name)
      backup.complete!
    else
      backup.failed!
    end
  rescue
    Rails.logger.info("failed")
    backup.failed!
    raise
{'fraction_non_alphanumeric': 0.10925644916540213, 'fraction_numerical': 0.0037936267071320183, 'mean_word_length': 4.190944881889764, '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': '2720815', 'n_tokens_mistral': 799, 'n_tokens_neox': 797, 'n_words': 118}