<commit_before>require 'docker'
require 'dnsruby'

class DockerDNS

  #==========================================================================
  def self.run!(config)
    DockerDNS.new(config).run!
  end
  #==========================================================================

  def initialize(config)
    @config = config
  end

  def domain
	  @config["domain"]
  end

  def reversezone
	  @config["reversezone"]
  end

  def resolver
    @resolver ||= Dnsruby::Resolver.new(@config['dnsserver'])
  end

  def ttl
    @config["ttl"]
  end

  def docker_url
    @config["dockerurl"] || '/var/run/docker.sock'
  end

  def run!
  	Docker.url = docker_url
  	Docker.options[:read_timeout] = 5
    begin
  		Docker::Event.stream do |event|
  		  case event.status
        when "create"
  			  next
  		  when "start"
  			  puts "caught event #{event.status} for container id #{event.id}"
  			  create_or_update_dns_records!(event.id, domain)
  		  when "die", "kill", "stop", "destroy"
  			  puts "caught event #{event.status} for container id #{event.id}"
  			  delete_dns_records!(event.id)
  		  else
  			  puts "Ignoring Docker Event #{event.status}"
  		  end
  		end
  	rescue Docker::Error::TimeoutError, Excon::Errors::SocketError
  		retry
  	rescue StandardException => e
  		puts "Error while streaming events: #{e}"<commit_msg>fixed exection handlin in run() function<commit_after>require 'docker'
require 'dnsruby'

class DockerDNS

  #==========================================================================
  def self.run!(config)
    DockerDNS.new(config).run!
  end
  #==========================================================================

  def initialize(config)
    @config = config
  end

  def domain
	  @config["domain"]
  end

  def reversezone
	  @config["reversezone"]
  end

  def resolver
    @resolver ||= Dnsruby::Resolver.new(@config['dnsserver'])
  end

  def ttl
    @config["ttl"]
  end

  def docker_url
    @config["dockerurl"] || '/var/run/docker.sock'
  end

  def run!
  	Docker.url = docker_url
  	Docker.options[:read_timeout] = 5
    begin
  		Docker::Event.stream do |event|
  		  case event.status
        when "create"
  			  next
  		  when "start"
  			  puts "caught event #{event.status} for container id #{event.id}"
  			  create_or_update_dns_records!(event.id, domain)
  		  when "die", "kill", "stop", "destroy"
  			  puts "caught event #{event.status} for container id #{event.id}"
  			  delete_dns_records!(event.id)
  		  else
  			  puts "Ignoring Docker Event #{event.status}"
  		  end
  		end
  	rescue Docker::Error::TimeoutError, Excon::Errors::SocketError
  		retry
  	rescue StandardError => e
  		puts "Error while streaming events: #{e}"
{'fraction_non_alphanumeric': 0.21577981651376146, 'fraction_numerical': 0.0007339449541284404, 'mean_word_length': 3.411003236245955, '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': '2082148', 'n_tokens_mistral': 955, 'n_tokens_neox': 870, 'n_words': 202}