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.



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

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



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

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

  if @action_ownership_channel &&
      @action_ownership_channel.remote_actions_exist?
    log_error("[error] Unprocessed actions are left in action_ownership_channel queue #{@action_ownership_channel.dump}")
  end
end

#before_runObject

ServerEngine hook point



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

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



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

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

#initializeObject



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

def initialize
  super
  $log = logger
end

#reload_configObject

ServerEngine hook point



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

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

#setup_log_formatObject



71
72
73
74
75
76
# File 'lib/flydata/helper/server.rb', line 71

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