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.



27
28
29
# File 'lib/flydata/helper/server.rb', line 27

def action_ownership_channel
  @action_ownership_channel
end

Class Method Details

.run(opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/flydata/helper/server.rb', line 14

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



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

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

#before_runObject

ServerEngine hook point



40
41
42
43
44
45
46
# File 'lib/flydata/helper/server.rb', line 40

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



54
55
56
# File 'lib/flydata/helper/server.rb', line 54

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

#initializeObject



23
24
25
# File 'lib/flydata/helper/server.rb', line 23

def initialize
  super
end

#reload_configObject

ServerEngine hook point



30
31
32
33
34
35
36
37
# File 'lib/flydata/helper/server.rb', line 30

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

#setup_log_formatObject



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

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