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
|
# File 'lib/ydim/server.rb', line 23
def initialize(config, logger)
@serv = Needle::Registry.new
@serv.register(:auth_server) {
auth = RRBA::Server.new
root = RootUser.new(:root)
root.name = config.root_name
root.email = config.root_email
root_key = config.root_key
path = File.expand_path(root_key, config.conf_dir)
path_or_key = File.exist?(path) ? path : root_key
root.public_key = Util.load_key(path_or_key)
auth.root = root
auth
}
@serv.register(:clients) {
ClientHandler.new(@serv)
}
@serv.register(:config) {
config
}
@serv.register(:currency_converter) {
ODBA.cache.fetch_named('currency_converter', self) {
CurrencyConverter.new
}
}
@serv.register(:factory) {
Factory.new(@serv)
}
@serv.register(:id_server) {
ODBA.cache.fetch_named('id_server', self) {
ODBA::IdServer.new
}
}
@serv.register(:logger) {
logger
}
if(hour = config.autoinvoice_hour)
@autoinvoicer = repeat_at(hour, 'AutoInvoicer') {
AutoInvoicer.new(@serv).run
}
end
if(hour = config.currency_update_hour)
if(@serv.currency_converter.known_currencies \
< @serv.config.currencies.size)
CurrencyUpdater.new(@serv).run
end
@currency_updater = repeat_at(hour, 'CurrencyUpdater') {
CurrencyUpdater.new(@serv).run
}
end
@status_updater = repeat_at(1, 'StatusUpdater') {
Invoice.all { |inv| inv.save }
}
@sessions = []
end
|