<commit_before>module Rapns
  module Daemon
    class AppRunner
      class << self
        attr_reader :runners # TODO: Needed?
      end

      @runners = {}

      def self.enqueue(notification)
        if app = @runners[notification.app_id]
          app.enqueue(notification)
        else
          Rapns::Daemon.logger.error("No such app '#{notification.app_id}' for notification #{notification.id}.")
        end
      end

      def self.sync
        apps = Rapns::App.all
        apps.each { |app| sync_app(app) }
        removed = runners.keys - apps.map(&:id)
        removed.each { |app_id| runners.delete(app_id).stop }
      end

      def self.sync_app(app)
        if runners[app.id]
          runners[app.id].sync(app)
        else
          runner = new_runner(app)
          begin
            runner.start
            runners[app.id] = runner
          rescue StandardError => e
            Rapns::Daemon.logger.error("[#{app.name}] Exception raised during startup. Notifications will not be delivered for this app.")
            Rapns::Daemon.logger.error(e)
          end
        end
      end

      def self.new_runner(app)
        type = app.class.parent.name.demodulize
        "Rapns::Daemon::#{type}::AppRunner".constantize
      end

      def self.stop
        @runners.values.map(&:stop)
      end

      def self.debug
        @runners.values.map(&:debug)
      end

      def self.idle
        runners.values.find_all { |runner| runner.idle? }
      end

      attr_reader :app
<commit_msg>Fix new_runner x 2.<commit_after>module Rapns
  module Daemon
    class AppRunner
      class << self
        attr_reader :runners # TODO: Needed?
      end

      @runners = {}

      def self.enqueue(notification)
        if app = @runners[notification.app_id]
          app.enqueue(notification)
        else
          Rapns::Daemon.logger.error("No such app '#{notification.app_id}' for notification #{notification.id}.")
        end
      end

      def self.sync
        apps = Rapns::App.all
        apps.each { |app| sync_app(app) }
        removed = runners.keys - apps.map(&:id)
        removed.each { |app_id| runners.delete(app_id).stop }
      end

      def self.sync_app(app)
        if runners[app.id]
          runners[app.id].sync(app)
        else
          runner = new_runner(app)
          begin
            runner.start
            runners[app.id] = runner
          rescue StandardError => e
            Rapns::Daemon.logger.error("[#{app.name}] Exception raised during startup. Notifications will not be delivered for this app.")
            Rapns::Daemon.logger.error(e)
          end
        end
      end

      def self.new_runner(app)
        type = app.class.parent.name.demodulize
        "Rapns::Daemon::#{type}::AppRunner".constantize.new(app)
      end

      def self.stop
        @runners.values.map(&:stop)
      end

      def self.debug
        @runners.values.map(&:debug)
      end

      def self.idle
        runners.values.find_all { |runner| runner.idle? }
      end

      attr_reader :app

{'fraction_non_alphanumeric': 0.10722458319712325, 'fraction_numerical': 0.00032690421706440013, 'mean_word_length': 1.8651685393258426, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4986741', 'n_tokens_mistral': 938, 'n_tokens_neox': 934, 'n_words': 199}