Show More
@@ -25,6 +25,8 b' import Queue' | |||
|
25 | 25 | import subprocess32 |
|
26 | 26 | import os |
|
27 | 27 | |
|
28 | ||
|
29 | from dateutil.parser import parse | |
|
28 | 30 | from pyramid.i18n import get_localizer |
|
29 | 31 | from pyramid.threadlocal import get_current_request |
|
30 | 32 | from pyramid.interfaces import IRoutesMapper |
@@ -127,16 +129,36 b' def write_metadata_if_needed(event):' | |||
|
127 | 129 | from rhodecode.lib import system_info |
|
128 | 130 | from rhodecode.lib import ext_json |
|
129 | 131 | |
|
132 | fname = '.rcmetadata.json' | |
|
133 | ini_loc = os.path.dirname(rhodecode.CONFIG.get('__file__')) | |
|
134 | metadata_destination = os.path.join(ini_loc, fname) | |
|
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 | ||
|
130 | 148 | def write(): |
|
131 | fname = '.rcmetadata.json' | |
|
132 | ini_loc = os.path.dirname(rhodecode.CONFIG.get('__file__')) | |
|
133 | metadata_destination = os.path.join(ini_loc, fname) | |
|
134 | ||
|
135 | 149 | configuration = system_info.SysInfo( |
|
136 | 150 | system_info.rhodecode_config)()['value'] |
|
137 | 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 | 159 | dbinfo = system_info.SysInfo(system_info.database_info)()['value'] |
|
139 | 160 | del dbinfo['url'] |
|
161 | ||
|
140 | 162 | metadata = dict( |
|
141 | 163 | desc='upgrade metadata info', |
|
142 | 164 | license_token=license_token, |
@@ -146,6 +168,7 b' def write_metadata_if_needed(event):' | |||
|
146 | 168 | database=dbinfo, |
|
147 | 169 | cpu=system_info.SysInfo(system_info.cpu)()['value'], |
|
148 | 170 | memory=system_info.SysInfo(system_info.memory)()['value'], |
|
171 | setup=setup | |
|
149 | 172 | ) |
|
150 | 173 | |
|
151 | 174 | with open(metadata_destination, 'wb') as f: |
@@ -155,6 +178,15 b' def write_metadata_if_needed(event):' | |||
|
155 | 178 | if settings.get('metadata.skip'): |
|
156 | 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 | 190 | try: |
|
159 | 191 | write() |
|
160 | 192 | except Exception: |
General Comments 0
You need to be logged in to leave comments.
Login now