Sha256: 5257f281e1288c37ba387e70e21d7dee9ead51056614d448046bc3ddccc10283

Contents?: true

Size: 1.58 KB

Versions: 29

Compression:

Stored size: 1.58 KB

Contents

require 'serverengine'
require 'flydata-core/logger'

module Flydata
  module Helper
    module Server
      include FlydataCore::Logger

      OVERWRITE_PARAMETERS = {
        :worker_type => 'thread',
        :supervisor => true,
      }

      def self.run(opts={})
        # See ServerEngine documents for details:
        # https://github.com/frsyuki/serverengine
        ServerEngine.create(Server, Worker) do
          ConfigParser.parse_file(opts[:config_path]).
            merge(opts).merge(OVERWRITE_PARAMETERS)
        end.run
      end

      def initialize
        super
      end

      attr_reader :action_ownership_channel

      # ServerEngine hook point
      def reload_config
        super
        setup_log_format
        log_info "reload_config"
        if @scheduler
          @scheduler.reload(config[:helper])
        end
      end

      # ServerEngine hook point
      def before_run
        log_debug "before_run"
        helper_config = config[:helper]
        @action_ownership_channel = ActionOwnershipChannel.new
        @scheduler = Scheduler.new(helper_config, self)
        @scheduler.start
      end

      # ServerEngine hook point
      def after_run
        log_debug "after_run"
        @scheduler.shutdown if @scheduler
      end

      def custom_log_items
        super.merge(prefix: '[server]')
      end

      def setup_log_format
        logger.datetime_format = "%Y-%m-%d %H:%M:%S %z "
        logger.formatter = proc do |severity, datetime, progname, msg|
          "#{datetime} helper.#{severity.to_s.downcase}: #{msg}\n"
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
flydata-0.6.4 lib/flydata/helper/server.rb
flydata-0.6.3 lib/flydata/helper/server.rb
flydata-0.6.2 lib/flydata/helper/server.rb
flydata-0.6.1 lib/flydata/helper/server.rb
flydata-0.6.0 lib/flydata/helper/server.rb
flydata-0.5.21 lib/flydata/helper/server.rb
flydata-0.5.20 lib/flydata/helper/server.rb
flydata-0.5.17 lib/flydata/helper/server.rb
flydata-0.5.16 lib/flydata/helper/server.rb
flydata-0.5.15 lib/flydata/helper/server.rb
flydata-0.5.14 lib/flydata/helper/server.rb
flydata-0.5.13 lib/flydata/helper/server.rb
flydata-0.5.12 lib/flydata/helper/server.rb
flydata-0.5.11 lib/flydata/helper/server.rb
flydata-0.5.10 lib/flydata/helper/server.rb
flydata-0.5.9 lib/flydata/helper/server.rb
flydata-0.5.8 lib/flydata/helper/server.rb
flydata-0.5.7 lib/flydata/helper/server.rb
flydata-0.5.6 lib/flydata/helper/server.rb
flydata-0.5.5 lib/flydata/helper/server.rb