Module: Flydata::Helper::Server

Includes:
FlydataCore::Logger
Defined in:
lib/flydata/helper/server.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_ownership_channelObject (readonly)

Returns the value of attribute action_ownership_channel.



34
35
36
# File 'lib/flydata/helper/server.rb', line 34

def action_ownership_channel
  @action_ownership_channel
end

Class Method Details

.run(opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/flydata/helper/server.rb', line 21

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

Instance Method Details

#after_runObject

ServerEngine hook point



56
57
58
59
# File 'lib/flydata/helper/server.rb', line 56

def after_run
  log_debug "after_run"
  @scheduler.shutdown if @scheduler
end

#before_runObject

ServerEngine hook point



47
48
49
50
51
52
53
# File 'lib/flydata/helper/server.rb', line 47

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

#custom_log_itemsObject



61
62
63
# File 'lib/flydata/helper/server.rb', line 61

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

#initializeObject



30
31
32
# File 'lib/flydata/helper/server.rb', line 30

def initialize
  super
end

#reload_configObject

ServerEngine hook point



37
38
39
40
41
42
43
44
# File 'lib/flydata/helper/server.rb', line 37

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

#setup_log_formatObject



65
66
67
68
69
70
# File 'lib/flydata/helper/server.rb', line 65

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