<commit_before>class AutoReceiveDossiersForProcedureJob < ApplicationJob
  queue_as :cron

  def perform(procedure_id, state)
    procedure = Procedure.find(procedure_id)
    case state
    when Dossier.states.fetch(:en_instruction)
      procedure.dossiers.state_en_construction.update_all(
        state: Dossier.states.fetch(:en_instruction),
        en_instruction_at: DateTime.now
      )
    when Dossier.states.fetch(:accepte)
      procedure.dossiers.state_en_construction.find_each do |dossier|
        dossier.update(
          state: Dossier.states.fetch(:accepte),
          en_instruction_at: DateTime.now,
          processed_at: DateTime.now
        )
        dossier.attestation = dossier.build_attestation
        dossier.save
      end
    else
      raise "Receiving Procedure##{procedure_id} in invalid state \"#{state}\""
    end
  end
end<commit_msg>[Fix #2550] Also send mail notification when accepting dossier<commit_after>class AutoReceiveDossiersForProcedureJob < ApplicationJob
  queue_as :cron

  def perform(procedure_id, state)
    procedure = Procedure.find(procedure_id)
    case state
    when Dossier.states.fetch(:en_instruction)
      procedure.dossiers.state_en_construction.update_all(
        state: Dossier.states.fetch(:en_instruction),
        en_instruction_at: DateTime.now
      )
    when Dossier.states.fetch(:accepte)
      procedure.dossiers.state_en_construction.find_each do |dossier|
        dossier.update(
          state: Dossier.states.fetch(:accepte),
          en_instruction_at: DateTime.now,
          processed_at: DateTime.now
        )
        dossier.attestation = dossier.build_attestation
        dossier.save
        NotificationMailer.send_closed_notification(dossier).deliver_later
      end
    else
      raise "Receiving Procedure##{procedure_id} in invalid state \"#{state}\""
    end
  end
end
{'fraction_non_alphanumeric': 0.08190578158458243, 'fraction_numerical': 0.0021413276231263384, 'mean_word_length': 3.190582959641256, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5211394', 'n_tokens_mistral': 595, 'n_tokens_neox': 539, 'n_words': 100}