Sha256: 224cd7a41d21d24113aa03452eebdf9384de1808f98eee716b0e8ad4e177c310

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require 'liquid/metrics'
require 'liquid/tracker'

module Liquid
  class Server
    def initialize
      $log.info("#{self.class.name.downcase} #{RUBY_DESCRIPTION}")
      $log.info("#{self.class.name.downcase}", env: Env.mode)
      Signal.register_shutdown_handler { System.exit(0) }
      Signal.register_shutdown_handler { ZContext.destroy }
      initialize_raven
      initialize_tracker
      initialize_metrics
      initialize_health_checks
    end

    def initialize_raven
      return unless $conf.raven
      require 'raven'
      Raven.configure do |config|
        config.dsn = $conf.raven.dsn
        config.logger = $log
      end
      $log.add_exception_handler do |exc, message, attribs|
        Raven.capture_exception(exc)
      end
    end

    def initialize_tracker
      if $conf.tracker.kafka.enabled
        # http://kafka.apache.org/documentation.html#producerconfigs
        properties = java.util.Properties.new
        properties['metadata.broker.list'] = $conf.tracker.kafka.brokers.join(',')
        properties['producer.type'] = 'async'
        properties['serializer.class'] = 'kafka.serializer.StringEncoder'
        $tracker = ::Tracker::KafkaTracker.new(properties, $conf.tracker.dimensions)
      else
        $tracker = ::Tracker::LoggerTracker.new($conf.tracker.dimensions)
      end
      Signal.register_shutdown_handler { $tracker.shutdown }
    end

    def initialize_metrics
      ::Metrics.start
      ::Metrics::TrackerReporter.new($tracker.with_topic('metrics'))
      Signal.register_shutdown_handler { ::Metrics.stop }
    end

    def initialize_health_checks
      Thread.new do
        Thread.name = "Health Check"
        HealthCheck.poll
      end
    end

    def initialize_zmachine
      require 'zmachine'
      ZMachine.logger = $log
      ZMachine.debug = true if $conf.zmachine.debug
      ZMachine.heartbeat_interval = 0.1
    end

    def run
      # by default wait for all workers
      Thread.join
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
liquid-ext-3.3.8 lib/liquid/server.rb