##// END OF EJS Templates
metadata: store workers and prevent to excesive metadata writes.
marcink -
r2488:e8ec1e05 default
parent child Browse files
Show More
@@ -25,6 +25,8 b' import Queue'
25 import subprocess32
25 import subprocess32
26 import os
26 import os
27
27
28
29 from dateutil.parser import parse
28 from pyramid.i18n import get_localizer
30 from pyramid.i18n import get_localizer
29 from pyramid.threadlocal import get_current_request
31 from pyramid.threadlocal import get_current_request
30 from pyramid.interfaces import IRoutesMapper
32 from pyramid.interfaces import IRoutesMapper
@@ -127,16 +129,36 b' def write_metadata_if_needed(event):'
127 from rhodecode.lib import system_info
129 from rhodecode.lib import system_info
128 from rhodecode.lib import ext_json
130 from rhodecode.lib import ext_json
129
131
130 def write():
131 fname = '.rcmetadata.json'
132 fname = '.rcmetadata.json'
132 ini_loc = os.path.dirname(rhodecode.CONFIG.get('__file__'))
133 ini_loc = os.path.dirname(rhodecode.CONFIG.get('__file__'))
133 metadata_destination = os.path.join(ini_loc, fname)
134 metadata_destination = os.path.join(ini_loc, fname)
134
135
136 def get_update_age():
137 now = datetime.datetime.utcnow()
138
139 with open(metadata_destination, 'rb') as f:
140 data = ext_json.json.loads(f.read())
141 if 'created_on' in data:
142 update_date = parse(data['created_on'])
143 diff = now - update_date
144 return diff.total_seconds() / 60.0
145
146 return 0
147
148 def write():
135 configuration = system_info.SysInfo(
149 configuration = system_info.SysInfo(
136 system_info.rhodecode_config)()['value']
150 system_info.rhodecode_config)()['value']
137 license_token = configuration['config']['license_token']
151 license_token = configuration['config']['license_token']
152
153 setup = dict(
154 workers=configuration['config']['server:main'].get(
155 'workers', '?'),
156 worker_type=configuration['config']['server:main'].get(
157 'worker_class', 'sync'),
158 )
138 dbinfo = system_info.SysInfo(system_info.database_info)()['value']
159 dbinfo = system_info.SysInfo(system_info.database_info)()['value']
139 del dbinfo['url']
160 del dbinfo['url']
161
140 metadata = dict(
162 metadata = dict(
141 desc='upgrade metadata info',
163 desc='upgrade metadata info',
142 license_token=license_token,
164 license_token=license_token,
@@ -146,6 +168,7 b' def write_metadata_if_needed(event):'
146 database=dbinfo,
168 database=dbinfo,
147 cpu=system_info.SysInfo(system_info.cpu)()['value'],
169 cpu=system_info.SysInfo(system_info.cpu)()['value'],
148 memory=system_info.SysInfo(system_info.memory)()['value'],
170 memory=system_info.SysInfo(system_info.memory)()['value'],
171 setup=setup
149 )
172 )
150
173
151 with open(metadata_destination, 'wb') as f:
174 with open(metadata_destination, 'wb') as f:
@@ -155,6 +178,15 b' def write_metadata_if_needed(event):'
155 if settings.get('metadata.skip'):
178 if settings.get('metadata.skip'):
156 return
179 return
157
180
181 # only write this every 24h, workers restart caused unwanted delays
182 try:
183 age_in_min = get_update_age()
184 except Exception:
185 age_in_min = 0
186
187 if age_in_min < 60 * 60 * 24:
188 return
189
158 try:
190 try:
159 write()
191 write()
160 except Exception:
192 except Exception:
General Comments 0
You need to be logged in to leave comments. Login now