<commit_before># -*- coding: utf-8 -*-

require "net/pop"

module Ans::EmailReceiver
  module Job
    def self.included(m)
      m.send :extend, ClassMethods
    end

    module ClassMethods
      def perform
        new.receive_all
      end
    end

    def receive_all
      host, port, user, password = config.host, config.port, config.user, config.password
      return if [host,port,user,password].any?{|s| s.blank?}

      EmailReceive.old.delete_all

      Net::POP3.start(host, port, user, password) do |pop|
        pop.mails.each{|mail| receive mail}
      end
    end
    def receive(mail)
      body = mail.pop
      EmailReceive.receive(body) do |email_receive|
        mailer.receive email_receive.body
        email_receive.reload
        mail.delete if email_receive.email_queue.present? || delete?(email_receive)
      end
    rescue => e
      log e, body
      error e, body
    end

    private

    def mail_name
      @mail_name ||= self.class.to_s.gsub(/Receiver$/, "").underscore
    end
    def config
      @config ||= Config.new mail_name
    end
    def mailer
      @mailer ||= "#{mail_name.camelize}Mailer".constantize
    end

    def delete?(email_receive)
      false
    end

    def log(e,mail)
      logger = Logger.new("log/debug.log")
      logger.debug "========== Encode Error =========="
      logger.debug "#{e.inspect}"
      logger.debug mail
    end
    def error(e,mail)
    end

  end
end
<commit_msg>ログの取り方を修正<commit_after># -*- coding: utf-8 -*-

require "net/pop"

module Ans::EmailReceiver
  module Job
    def self.included(m)
      m.send :extend, ClassMethods
    end

    module ClassMethods
      def perform
        new.receive_all
      end
    end

    def receive_all
      host, port, user, password = config.host, config.port, config.user, config.password
      return if [host,port,user,password].any?{|s| s.blank?}

      EmailReceive.old.delete_all

      Net::POP3.start(host, port, user, password) do |pop|
        pop.mails.each{|mail| receive mail}
      end
    end
    def receive(mail)
      body = mail.pop
      EmailReceive.receive(body) do |email_receive|
        mailer.receive email_receive.body
        email_receive.reload
        mail.delete if email_receive.email_queue.present? || delete?(email_receive)
      end
    rescue => e
      log e, body
      error e, body
    end

    private

    def mail_name
      @mail_name ||= self.class.to_s.gsub(/Receiver$/, "").underscore
    end
    def config
      @config ||= Config.new mail_name
    end
    def mailer
      @mailer ||= "#{mail_name.camelize}Mailer".constantize
    end

    def delete?(email_receive)
      false
    end

    def log(e,mail)
      File.open Rails.root.join("log/debug.log"), "a" do |f|
        f.puts "========== Encode Error =========="
        f.puts "#{e.inspect}"
        f.puts mail
      end
    end
    def error(e,mail)
    end

  end
end

{'fraction_non_alphanumeric': 0.11958762886597939, 'fraction_numerical': 0.0013745704467353953, 'mean_word_length': 2.2707865168539327, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6318341', 'n_tokens_mistral': 988, 'n_tokens_neox': 939, 'n_words': 226}