<commit_before># encoding: utf-8
require 'celluloid'
require 'net/ping/tcp'
require "sinatra/base"
require "slim"

module Finch
  class App < Sinatra::Base
    helpers do
      def class_for_status(state)
        state == :ok ? "success" : "error"
      end
    end

    get "/" do
      slim :ping, locals: {pings: settings.pings.map do |ping|
        Celluloid::Actor[ping]
      end
      }
    end
  end

  class Pinger
    include Celluloid
    attr_reader   :timer, :host, :port, :group
    attr_accessor :last_success, :state, :name

    def initialize(name, opts = {})
      @name = name
      @host = opts.fetch(:host, "localhost")
      @group = opts.fetch(:group, "Default")
      @port = opts.fetch(:port, lambda { raise(ArgumentError) })
      @timer  = every(opts.fetch(:frequency, 30)) { ping }
      ping
    end

    def ping
      ping_accessor.ping ? success : error
    end

    private

    def success
      self.state = :ok
      self.last_success = Time.now.utc
    end

    def error
      self.state = :ko
    end

    def ping_accessor
      @ping_accessor ||= Net::Ping::TCP.new(host, port)
    end
  end

  class Declator
    attr_reader :pings

    def initialize
      @pings = []
    end

    def ping(name, opts)
      pings << name
      Pinger.supervise_as(name, name, opts)
    end
  end

  def declare
    yield declarator = Declator.new
    App.set :pings, declarator.pings
  end

  module_function :declare
end
<commit_msg>Call first ping asynchronously for a faster boot<commit_after># encoding: utf-8
require 'celluloid'
require 'net/ping/tcp'
require "sinatra/base"
require "slim"

module Finch
  class App < Sinatra::Base
    helpers do
      def class_for_status(state)
        state == :ok ? "success" : "error"
      end
    end

    get "/" do
      slim :ping, locals: {pings: settings.pings.map do |ping|
        Celluloid::Actor[ping]
      end
      }
    end
  end

  class Pinger
    include Celluloid
    attr_reader   :timer, :host, :port, :group
    attr_accessor :last_success, :state, :name

    def initialize(name, opts = {})
      @name = name
      @host = opts.fetch(:host, "localhost")
      @group = opts.fetch(:group, "Default")
      @port = opts.fetch(:port, lambda { raise(ArgumentError) })
      @timer  = every(opts.fetch(:frequency, 30)) { ping }
      async.ping
    end

    def ping
      ping_accessor.ping ? success : error
    end

    private

    def success
      self.state = :ok
      self.last_success = Time.now.utc
    end

    def error
      self.state = :ko
    end

    def ping_accessor
      @ping_accessor ||= Net::Ping::TCP.new(host, port)
    end
  end

  class Declator
    attr_reader :pings

    def initialize
      @pings = []
    end

    def ping(name, opts)
      pings << name
      Pinger.supervise_as(name, name, opts)
    end
  end

  def declare
    yield declarator = Declator.new
    App.set :pings, declarator.pings
  end

  module_function :declare
end

{'fraction_non_alphanumeric': 0.10489038785834738, 'fraction_numerical': 0.002023608768971332, 'mean_word_length': 2.3139664804469273, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6557961', 'n_tokens_mistral': 1022, 'n_tokens_neox': 980, 'n_words': 265}