This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
/
aggregator.rb
93 lines (68 loc) · 1.88 KB
/
aggregator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'conf/initializers/server_initializer'
require 'conf/initializers/database_initializer'
require 'conf/initializers/console_initializer'
require 'app/plugins/plugin_manager'
require 'app/utils/argument_parser'
require 'app/utils/logging'
require 'app/utils/setting'
# Main class
class Aggregator
include Logging
include Setting
# Set aggregator version
AGGREGATOR_VERSION = '0.0.1' unless const_defined?(:AGGREGATOR_VERSION)
# Set default environment
@environment = :production
attr_reader :stop
# Initialize the whole system
def initialize(internal_server = false, arguments = [])
options = ArgumentParser.parse(arguments)
logger.info "Using #{options.environment} environment"
Aggregator.environment = options.environment
Logging::environment Aggregator.environment
Logging::quiet = true if options.quiet
logger.info 'Starting up aggregator now'
DatabaseInitializer.new(options.environment)
if options.console
ConsoleInitializer.new(options.environment)
elsif Aggregator.environment != :test
Aggregator.plugin_manager = PluginManager.new
ServerInitializer.new if internal_server
logger.info "Aggregator is up and running"
Signal.trap("SIGINT") do
Thread.current.exit
end
start
end
end
# Returns the environment
def self.environment
@environment
end
# Returns the plugin manager
def self.plugin_manager
@plugin_manager
end
# Shutdown the system
def self.shutdown
@stop = true
end
private
def self.environment=(value)
@environment = value
end
def self.plugin_manager=(value)
@plugin_manager = value
end
def start
until @stop
Aggregator.plugin_manager.run
logger.info "Aggregation done. Next aggregation in #{setting.aggregate_timer} seconds."
sleep setting.aggregate_timer
end
end
end
if __FILE__ == $PROGRAM_NAME
app = Aggregator.new(true, ARGV)
end