-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
39 lines (32 loc) · 937 Bytes
/
config.py
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
import os
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
defaults = {
"heartbeat_interval": 10,
"checkpoint_interval": 300,
"keep_n_checkpoints": 3,
"wal_dir": "trie_wal",
"checkpoint_dir": "trie_checkpoints",
"replication_factor": 1,
}
class Config():
def __init__(self, filepath):
self.filepath = filepath
@property
def node_id(self):
# TODO: something better
return os.getenv("HOSTNAME", "http://127.0.0.1:8000")
def current(self):
stream = open(self.filepath, 'r')
# TODO: cached struct
return defaults | load(stream, Loader=Loader)
def heartbeat_interval(self):
return self.current()["heartbeat_interval"]
def checkpoint_interval(self):
return self.current()["checkpoint_interval"]
@property
def replication_factor(self):
return self.current()["replication_factor"]